AS3 Loop Benchmarks (with results + files)

Hey everybody, I was wondering about some AS3 loop benchmarks and decided to do some timer tests for all the loops, because a lot of the information I found online seemed to either be out of date or inconclusive. I put in just about every type of loop I could think of off the top of my head (at least the straightforward ones) and here are the files and results:

before I make any conclusions I thought I would put this up here for you guys to look at and see if I have any of the loops implemented wrong or have anything that could affect performance. Also if you have any other types of loops you would like me to add, please post them and I will try to include them over the next few days. I used counters to make sure that each loop had the exact same number of iterations, but if you see an error in anything please let me know.

assumptions I have made:

  1. <= and >= have the same evaluation speed as < and >
  2. i can use an int type set to -1 for the starting index for some loops without impacting speed
  3. the order i call my test functions does not affect their performance

i probably should test these all separately and get an average, but I thought I would make sure I haven’t done something horribly wrong before I proceed:

anyways, here are the results, for 1000000 iterations, published for FP9 at 31fps.
I am on WindowsXP, running an AMD Athlon 64 Processor at 2.01 GHz with 2 gigs of ram.
the read test reads int values into a local variable from a prepopulated array.
the write tests pushes the index of the loop to an empty array. please see the files for more info, looking forward to your responses.

whileLoopEmpty1: while(i < n){i++} -> 7ms
whileLoopEmpty2: while(i > 0){i–} -> 5ms
whileLoopEmpty3: while(i < n){++i} -> 7ms
whileLoopEmpty4: while(i > 0){–i} -> 7ms
whileLoopEmpty5: while(i++ < n){} -> 6ms
whileLoopEmpty6: while(i-- > 0){} -> 8ms
whileLoopEmpty7: while(++i < n){} -> 6ms
whileLoopEmpty8: while(–i >= 0){} -> 5ms
whileLoopRead1: while(i < n){i++} -> 23ms
whileLoopRead2: while(i > 0){i–} -> 22ms
whileLoopRead3: while(i < n){++i} -> 23ms
whileLoopRead4: while(i > 0){–i} -> 22ms
whileLoopRead5: while(i++ < n){} -> 28ms
whileLoopRead6: while(i-- > 0){} -> 22ms
whileLoopRead7: while(++i < n){} -> 22ms
whileLoopRead8: while(–i >= 0){} -> 20ms
whileLoopWrite1: while(i < n){i++} -> 202ms
whileLoopWrite2: while(i > 0){i–} -> 183ms
whileLoopWrite3: while(i < n){++i} -> 183ms
whileLoopWrite4: while(i > 0){–i} -> 221ms
whileLoopWrite5: while(i++ < n){} -> 182ms
whileLoopWrite6: while(i-- > 0){} -> 193ms
whileLoopWrite7: while(++i < n){} -> 209ms
whileLoopWrite8: while(–i >= 0){} -> 181ms
forLoopEmpty1: for(i = 0; i < n; i++){} -> 8ms
forLoopEmpty2: for(i = n; i >= 0; i–){} -> 6ms
forLoopEmpty3: for(i = 0; i < n; ++i){} -> 7ms
forLoopEmpty4: for(i = n; i >= 0; --i){} -> 7ms
forLoopRead1:for(i = 0; i < n; i++){} -> 21ms
forLoopRead2: for(i = n; i >= 0; i–){} -> 23ms
forLoopRead3: for(i = 0; i < n; ++i){} -> 23ms
forLoopRead4: for(i = n; i >= 0; --i){} -> 22ms
forLoopWrite1: for(i = 0; i < n; i++){} -> 188ms
forLoopWrite2: for(i = n; i >= 0; i–){} -> 187ms
forLoopWrite3: for(i = 0; i < n; ++i){} -> 245ms
forLoopWrite4: for(i = n; i >= 0; --i){} -> 193ms
forInEmpty: for(i in array){} -> 792ms
forInAssign: for(i in array){} -> 3807ms
forInWrite: for(i in array){} -> 3858ms
forEachInEmpty: for each(i in array){} -> 43ms
forEachInAssign: for each(i in array){} -> 43ms
forEachInWrite: for each(i in array){} -> 260ms