[DUG] Curious re efficiency of using in [set of integer]

Ross Levis ross at stationplaylist.com
Mon Aug 15 22:51:22 NZST 2022


I did the test but had to use a loop 40000000 times to get some separation.  The in set statement was actually faster than doing 2 “or” statements.  Around 76 to 65 ticks.  Basically identical and both too fast to be concerned with.

 

From: delphi-bounces at listserver.123.net.nz [mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Ross Levis
Sent: Monday, 15 August 2022 6:11 pm
To: 'NZ Borland Developers Group - Delphi List'
Cc: delphi at delphi.org.nz
Subject: Re: [DUG] Curious re efficiency of using in [set of integer]

 

I should do that.

 

It may matter if it’s converting to something expensive code in ASM, and this code is being executed a few thousand times.

 

From: delphi-bounces at listserver.123.net.nz [mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Rohit Gupta
Sent: Monday, 15 August 2022 6:01 pm
To: NZ Borland Developers Group - Delphi List
Cc: delphi at delphi.org.nz
Subject: Re: [DUG] Curious re efficiency of using in [set of integer]

 

Just put it in a loop of 10k and time it. 

But honestly, does it really matter? 

Regards 
Rohit 

 

15/08/2022 17:34:14 Ross Levis <ross at stationplaylist.com>:

Var Total: Integer;

If I want to test 2 or 3 values of an integer, I often use

if Total in [4,6] then ...

But is that more or less efficient for the CPU/ASM coding than

if (Total = 4) or (Total = 6) then ...

I’m not sure how to find out myself.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20220815/9a8ebfab/attachment-0003.html 


More information about the Delphi mailing list