Gary Rosenzweig's

Developer Dispatch

News and Notes For Developers Using Flash, ActionScript, Director, PHP and JavaScript.


MY BLOGS
Developer Dispatch Blog
Flash Game U
iPhone Dispatch Blog
INFO & FEEDBACK
About Developer Dispatch
About Gary Rosenzweig
Gary Rosenzweig's Books
Feedback
Contact Gary Rosenzweig
SHARING
Add to Technorati Favorites
Add to Del.icio.us
Stumble Upon
LINKS TO MY SITES
CleverMedia
Fun Games at GameScene.com
MacMost
Director Online
LINKS TO MY FRIENDS
Tech Support from Ask Dave Taylor
Ask Leo
Amy Gahran
Custom Stickers
Dean's Director Tutorials
Flash Website Templates
Time 4 Learning
RSS FEEDS
Raw RSS
Add RSS to your My Yahoo


04/23/07

ActionScript 3.0 Speed Tests

Exactly how fast is ActionScript 3? Depending on what you test, either slightly faster, 100x or 1,000 xtimes as fast as ActionScript 2. Here are three tests that I performed. All were done on my MacBook Pro.
The first test is for animation. One thousand 20×20 red circles are copied from the Library and places randomly on the stage. They all travel at a diagonal, one pixel per frame. They bounce off the walls. After 100 frames, a frames-per-second calculation is shown. Both movies are set to 120fps, but the Flash 8 movie only manages 6 fps after moving all 1,000 circles. The Flash 9 movie was getting 15 fps. The results weren’t quite as dramatic in the browser, as it was 10fps for Flash 8 and 12fps for Flash 9.


Flash 8 Animation Test: fpstest8.swf


Flash 9 Animation Test: fpstest9.swf


The second test was for string handling. I created a 100,000 character string from random capital letters. Then I loop through them and compare each character to the next one to find matches. Only the comparison loop was timed. The Flash 8 movie took 4,500 milliseconds to finish the task. The Flash 9 movie took 43. That’s more than 100 times the speed.


Flash 8 String Test: stringtest8.swf


Flash 9 String Text: stringtest9.swf


The final test was for math. I wanted to keep it simple, so I only used addition. I loop one million times, adding i+i. That’s it. Flash 8 did it in 6,800 milliseconds. Flash 9 took 102 milliseconds.


Flash 8 Math Test: mathtest8.swf


Flash 9 Math Text: mathtest9.swf


But wait, there’s more. To keep things fair, I used the “Number” variable type in the Flash 9 example. After all, Flash 8 only has “Number”. But when I used the “int” type in the Flash 9 example, the sepped of one million additions was 5 milliseconds!


Now these are pretty simple tests, but I think they show there is a lot of potential in the new ActionScript 3.0. The 2nd and 3rd examples are using exactly the same code syntax, which is what I was going for when writing them. The difference is that ActionScript 2.0 created by Flash 8 is executed by the older ActionScript engine in the Flash plugin. While ActionScript 3.0 code is executed by the new engine.

Try these tests out and post a comment with your results. Be sure to include the hardware and OS you are using. Love to see some Linux comparisons too.


9 Responses to “ActionScript 3.0 Speed Tests”

  1. Raman Says:

    On my iBook (1.42GHz w/ 10.4.9) my numbers were a bit slower than yours but same ballpark.


    I’m curious about the speed of Director for some of these tasks…guess I’ll have to try that when I get a few spare moments.


  2. maliboo Says:

    Can you post your benchmark code?


  3. Raman Says:

    On my dual 2.7GHz water cooled Mac my times were slower than my iBook! I do have far more things sucking up CPU here…so very unscientific :) For the three tests using Flash 9.


    Animation, 11 fps

    String, 59 ms

    Math, 230 ms


    Just for fun I ran similar tests using Director/Shockwave.


    Animation, 33 fps

    String, 26569 ms

    Math, 215 ms


    I used imaging lingo for the animation. Much faster than Flash 9.


    The string handling in Director is brutal (as was expected). Something tells me using the PRegEx Xtra would drastically speed that up, or even Javascript. For comparing chunks I used aStr.char[i] = aStr.char[i+1] (not sure if that is the best approach).


    Math was ballpark of Flash 9. I wonder how Flash 9 does with more complex math. I can’t wait to get my copy of CS3.


  4. Projectmanagement Says:

    hmm,


    So Lingo is still faster. Any news of adding actionscript 3.0 in the next release of Director?


    M.


  5. alex Says:

    Raman,

    the string test can’t be made on mac with director, as director seems to have a major bug in handling string > 32K.

    Try the same test on a PC, it will give you proper results.

    As a general advice: when dealing with any strings in director for a x-platform app, always make sure to split the string up into chunks of


  6. alex Says:

    unfortunately my message got truncated :-(

    let’s see, if I can remember the rest…


    …always make sure to split the string up into chunks of


  7. alex Says:

    AHA! now I see, it was the “less then” char, which truncated the message


    unfortunately my message got truncated :-(

    let’s see, if I can remember the rest…


    …always make sure to split the string up into chunks of “less than” 32K, if you test on a mac. I have seen the best results with strings of 8 K length. Although it means, more search processes, it is MUCH faster!

    On windows, it is a tad slower to break the string up, but not noticeably, so for x-platform projects I do not make the distinction.

    If you ask me, it is simply a major bug in the lingo mac engine.


    Another thing, which came to mind, is that it may not be fair to compare IL to the circels which seem to be vectors. On the other hand, I vaguely remember that the flash 8 engine speeded up performance by caching the bitmaps of the same vector shape instances. so the red circles may in fact be bitmaps internally, which would make your comparisons to IL fair again :-)


    Thanks for sharing the test Gary, it’s very interesting. my results on this PB G4 1.25 Ghz are:

    3 FPS / 4 FPS

    4503 / 125

    8400 / 432


    impressive!

    I wish lingo had undergone such a change sometime in the last decade!

    But we are pretty much still at the state of 1999 :-(

    (Although one must confess, that we were pretty much ahead of time back then, we seem to loose ground every day)


  8. rideforever Says:

    Well since Flash was launched Macromedia/Adobe have been saying “it’s faster, it’s faster, it’s faster” ! It’s a bit like an estate agent telling you that you are buying a flat in the “Ever Popular X Area” … it should send alarm bells ringing.


    It would be interesting for someone to do comparative tests of :


    Flash 9 vs Director vs Silverlight


    … and then we would know something interesting.


    Volunteers ?


  9. MrSteel Says:

    for director test we should all wait new release

    I think we will all be astonished

    but if you compare director with anything java would be the choice

    at least for graphics


Leave a Reply