HIDIHO!

flash and you and me and you

loops : and the winner is …

TAGS: None

yesterday still, my fellow boss (and nonetheless friend) Aurélien noticed that the ‘++’ increment operator was slower than the ‘+=1′ operator, it deserved a bench :)

… an int typed increment + a Number typed maximum in a for( int = 0; int < Number; i++ ) loop!
unbelieivable you'll say, so did I yet check the benchmarks hereunder.
default is a 10.000.000 iterations loop.

firstly, let's try to loop with an int typed maximum value:

secondly trying to loop with a uint typed max:


and finally, let’s rock and roll ; the Number typed maximum value:


you can get the sources here:

morality:

  • typing is crucial
  • for++ and a Number() typed maximum value kills them all
  • some combiantions give better results than others
  • it’s unfair but life is unfair

ok as I am not the first man on earth, here are two links to much more skilled people than me who worked on the topic (optimization):

plus of course the big chiefs ( AM, Skinner etc.)

TAGS: None

4 Responses to “loops : and the winner is …”


  1. Mario Klingemann
    on Jul 12th, 2008
    @ 4:08 pm

    Strangely enough I am getting different results when I run your tests in my browser. I am seeing while++ and while — with int as a winner.


  2. nicoptere
    on Jul 12th, 2008
    @ 4:25 pm

    hi! thanks for coming
    I am on a MacBook / opera / FP9 which gives (almost always)
    int:
    for ++ method: 88 ms
    while ++ method: 81 ms
    while — method: 73 ms

    number:
    for ++ method: 44 ms
    while ++ method: 74 ms
    while — method: 76 ms

    but I guess it’s platform dependant + player dependant + whatever dependant :/
    it also seems that the decremental loops are a bit faster with the for loops.


  3. sitron
    on Jul 14th, 2008
    @ 12:06 pm

    well i guess the only “morality” is “never use for++ and uint”… (>140ms)
    for the rest…
    my best result is while++ with int (44ms)
    mac pro / firefox / flash9


  4. Hellsy
    on Apr 7th, 2009
    @ 7:31 pm

    for ++ method: 215 ms – Number
    for ++ method: 60 ms – uint
    for ++ method: 51 ms – int

Leave a Reply

© 2009 HIDIHO!. All Rights Reserved.

This blog is powered by Wordpress and Magatheme by Bryan Helmig.