He's right, and declaring the variable i inside of the loop rather than before actually (weirdly) runs faster. I don't know what pcode it produces, but I know CPU doesn't care about pcode. I think the only way to test speed is timing the thing. It's all very interesting, but I doubt even 10 ms of difference over 10,000 iterations could ever be noticable to the user. It certainly won't be the difference between a script timeout or not. I like the for..in for its simplicity ... also it helps avoid endless looping and other unexpected behavior if you're adding to or taking away from the array while the loop is running.
I agree, AS3 rocks! I'm done with 275 ms if I can have 7 ms. Thats 39 times faster! geesh Tyler On 9/19/06, JOR <[EMAIL PROTECTED]> wrote:
Actually, Tyler's tests proved that "var a in" is faster with today's player. I tried his test out myself and my results were even wider than his. I published for AS2 and ran in Flash Player 9. I was averaging roughly 265ms for "var a in" and 275ms for "(--a -(-1))". Then I compiled for AS3 and it ran too fast for testing at 7ms for both!!!! AS3/Player 9 rocks!!! So, I added another 9 to the loop counter making it 99999 iterations. Then "var a in" ran at 70ms, (--a -(-1)) and (a--) ran the same at 77ms. Then I added another 9 making the loops 999999. "var a in" ran at 740ms, (--a -(-1)) ran 765ms and (a--) at 770ms. I'm satisfied that "for (var a in array)" is faster than "while (--a -(-1))". Perhaps in the past that wasn't always the case, but with player 9 it is the case and that's what I'll be basing my decisions on. James O'Reilly http://www.jamesor.com Steven Sacks | BLITZ wrote: >>using a for..i..in loop will always be faster > > > It's been proven before here on flashcoders that for in is not faster > than --a -(-1) because it compiles to more lines of pcode. I guess it's > time to use Flasm to bust out some pcode and post it here on the list > instead of making claims based on hunches and past posts in the > archives. > > _______________________________________________ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
_______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com