in reply to Re: Efficient Looping Constructs
in thread Efficient Looping Constructs

My apologies. You are of course correct. In my defense I can only say that the two argument usage of the three argument for was a hasty addition, in order to be fair, after I noticed that its performance was better in other benchmarks that I did.

I corrected the fragment to the below

'for(;;)2' => '$sum=0; for (my $i=0;$i<=$n;) {$sum+=$i++}'
Which in itself is an instructive point, converting a 3 argument into a while(){} or simply by converting it into the 2 of 3 argment form, achieves a considerable speedup.

However while your point is fair I beleive that you will agree that in this case, luckily, this error did not affect the validity of the timings as the loop still performed the same set of iterations, and the sum was simply present to ensure (perhaps without reason) that perl did not optimize away empty blocks (perhaps inconsistently across the variation). The only difference being that as you said my error meant that that loop calculated 1..$n+1 instead of 0..$n.

Nevertheless should I make a similer post I shall endeavour to ensure that I dont make this type of mistake again.

:-)

Yves
--
You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)