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.

Posted on April 23, 2007 at 5:08 pm by Gary Rosenzweig · Permalink
In: General

9 Responses

Subscribe to comments via RSS

  1. Written by alex
    on 4/26/2007 at 11:16 pm
    Permalink

    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

  2. Written by alex
    on 4/28/2007 at 1:23 am
    Permalink

    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

  3. Written by alex
    on 4/28/2007 at 1:26 am
    Permalink

    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)

  4. Written by rideforever
    on 5/3/2007 at 2:31 am
    Permalink

    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 ?

Subscribe to comments via RSS