On Sun, 11 Dec 2005, Octavian Rasnita wrote: > Here is the test script: > > for(1 .. 50000000) { > $i += 1; > #$i = 1; > #$i++; > } > print times(); > > For $i += 1: 11.9210.03100 > > For $i = 1: 11.6250.01500 > > For $i++: 9.2960.03100 > > So, $i=1 takes 25.05% more time to run than $i++ and $i+=1 takes 28.24% more > time than $i++. > > I have made the test for more times, and the results were almost the same.
Sorry, I'm confused. These appear to do three different things. With $i += 1 the $i variable is declared once, then assigned 1 more 50_000_000 times. With $i = 1 the $i variable is assigned 1, 50_000_000 times. With $i++ the $i variable is incremented 50_000_000 times. It looks like the assignment is the bottleneck. After that, it looks like += is slightly slower because it has to look up and assign the value each time, while the other version is assigning a constant and so has been optimized at compile time. But that's mainly a guess... -- Chris Devers tìçÎÆgº
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>