Depends on the test. Testing "a" against 1, 2, no effective
difference. Testing against a set of numbers that are not in
sequence, no difference. Testing against a large set of numbers that
are in sequence, the "in" operator is more efficient. See attached
CPU screen captures.
One restriction is that "in" is limited to integers 0..255, so if you
need to test negative numbers or numbers greater than 255, you can't use "in".
The attached machine code is from XE2. Code from earlier or later
versions may vary. Hopefully they fixed the peephole optimization in
a later version (dec eax; sub eax,$06; can be replaced with just sub eax,$07;).
At 10:54 PM 6/7/2016, Ross Levis wrote:
I'm wondering which is more efficient to process...
if (a=1) or (a=2) then ...
or
if a in [1,2] then ...
Anyone know?
_______________________________________________
Delphi mailing list
[email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list
[email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi