Slow code generated for if...then...else
Original Reporter info from Mantis: lagprogramming
-
Reporter name:
Original Reporter info from Mantis: lagprogramming
- Reporter name:
Description:
Take a look at the following function:
function q(var x,c:integer):integer;
begin
if c=x then
Result:=1
else
Result:=0;
end;
If the function is called when x=c, then the code takes longer than when it is called with x<>c. This is not good because the "then" part should be executed faster than the "else" part.
Also, if x=c, when not optimized, the code runs faster than when having level 1, 2 or 3 optimizations.
If the same function is declared like one of the following two lines then everything is fine("then" part is executed faster then "else" part and turning on optimizations leads to faster code execution):
function q(x,c:integer):integer;
function q(const x,c:integer):integer;
Additional information:
This happens with both 2.6.2 and 2.6.4.
The attachment contains an example: set values '2' and '3' in the tedit and click the test tbutton to see the elapsed time.
Mantis conversion info:
- Mantis ID: 26089
- Version: 2.6.2