Benchmarking Flash 9

By C4RL05

While working on “Freddie” I realized that an old skool starfield would be a great benchmark for Flash 9.

It’s got a massively iterated loop, some simple Number calculations, plus BitmapData rendering. A good representation of the work I’m doing these days. It’s also relatively quick to program and most importantly, it looks good. Learning a new language is always painful, so let’s try to make it fun.

At first, without any AS3 specific optimization, it seemed to be up to 5x faster than the AS2 version. It was better than I expected, but the performance wasn’t consistent and there were a lot of slowdowns.

The compiler is *very* strict. Until you get used to it, you will get *a lot* of compile errors. But this is actually a good thing, as runtime errors will be hopefully reduced. It’s also quite helpful at pointing out the “Migration issues”.

Once I sat down and start to optimize the critical loop, performance raised spectacularly. I don’t believe there’s any problem with the AS2 version, as the code is almost identical and it’s not particularly slow considering the amount of stars it’s rendering.

In any case, the AS3 version is more than 20 times faster, at least on my machine*.

AS2 AS3
STARS 10,000 50,000
FPS 5 18
MS/FRAME 140 30

* Firefox running on a single core Centrino 1.6GHz laptop.

It’s very important that all variables are typed. Code execution becomes really slow and inconsistent if you just don’t bother. The same principle applies to using classes with public typed properties instead of Objects. Andre Michelle posted about this a while ago. You can also take a look at Adobe’s ActionScript 3.0 and AVM2: Performance Tuning for more info.

You can increase the number of stars up to 100,000, start again and toggle the bitmap clear for a Millenium Falcon hyperspace jump effect. Feel free to leave a comment with the performance on your machine or code improvements.

AS2 & AS3 versions + source code

17 Responses to “Benchmarking Flash 9”

  1. mr.doob Says:

    thx for the source code!

  2. Miles Says:

    Great example. Simple, but very effective. And the source code makes for interesting reading. Being able to make a direct comparison between the two, showing the steps involved in transitioning from AS2 to AS3, is very useful. Thanks.

    My stats, by the way:

    AS2:
    10,000 stars, 7 fps, 105 ms/f
    50,000 stars, 1 fps, 550 ms/f

    AS3:
    10,000 stars, 21 fps, 10 ms/f
    50,000 stars, 21 fps, 30 ms/f

    System
    Flash: 9,0,16,0
    Browser: IE 6
    OS: Windows XP Pro SP2
    CPU: Pentium4 3.2GHz
    RAM: 0.5GB

  3. nacho Says:

    ¿cómo se dice cojonudo en inglés? ;-)

    nice work, cool demo

  4. caché.yestoall.com » Blog Archive » actionscript3 vs actionscript2 Says:

    [...] ¿a que si carlos? [...]

  5. mr.doob Says:

    This is your fault ;)
    http://www.ricardocabello.com/?postid=270

  6. Daniel Says:

    Very nice, runs like a charm on my laptop.

  7. Nikolas Says:

    Sweet :)

  8. Lywyllyn Says:

    I am curious about the artist/album of the background music. Can you tell us ? :-)

  9. DonMoir Says:

    Performance is quite good in Flash 9. Here is another sample of Flash 9 performance. It is intended to push performace a bit, but not intended to drain the CPU. On slower machines, (2.6 ghz), it will use about 50 to 70 percent of the CPU. On faster machines, less than 10 percent CPU is used.

    Here’s the sample:

    http://sms.pangolin.com/starfire/

  10. webspacegames Says:

    We have a performance problem with our game FunnyTowers.com since we updated it to AS3. It works fine in FireFox and Safari but has become so slow in IE. In IE the processor jumps from 30% tot 80%. Does anybody know what causes this in IE.

  11. BIG SPACESHIP LABS / » Migrating from AS2 to AS3 Says:

    [...] dent in the market already. It helps that MySpace and YouTube both require Flash 9. It’s all far faster. The error messaging is much better, meaning when something breaks you’ll actually be able to [...]

  12. Flash 9 - The case for the client Says:

    [...] of great overviews have already been written about the language. The key features include a large speed boost, true XML support, and ECMAScript compliance. But more than that, AS3 represents a total shift to [...]

  13. Supersteil Blog | De media blog van Supersteil Says:

    [...] maanden. Dit komt vooral doordat Flash 9 een vereiste is voor MySpace en YouTube. Het is een stuk sneller. De foutmelding is veel beter en als laatste, XML zit standaard geïntegreerd. Het is nu super [...]

  14. Flash9 AS3 Market Now At 91% Penetration Availability « [ draw.logic ] Says:

    [...] AS2 & AS3  Versions of the star test to compare AS2 to AS3 so you can judge for yourself [source] [...]

  15. Vector Wars Update: HD Video « [ draw.logic ] Says:

    [...] 50,000 and is considerably more usable, in fact the AS2 version isn’t usable since it is slow. [source] This is a good test because it checks the movement of every pixel on the screen which leads me to [...]

  16. HD Video - Flash и Silverlight Says:

    [...] Вы можете посмотреть на рендер-тест, на работу AS 2 и AS 3 с пикселями. Это хороший тест, так как он наглядно демонстрирует, как AS 2 и AS 3 работают с пикселями, а значит и аналогично с видео. [...]

  17. Wwlnenuh Says:

    Thanks!,

Leave a Reply