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