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

September 25, 2006 at 2:33 am |
thx for the source code!
September 25, 2006 at 4:36 pm |
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
September 26, 2006 at 10:25 am |
¿cómo se dice cojonudo en inglés?
nice work, cool demo
September 26, 2006 at 10:32 am |
[...] ¿a que si carlos? [...]
September 27, 2006 at 1:22 pm |
This is your fault
http://www.ricardocabello.com/?postid=270
September 27, 2006 at 4:19 pm |
Very nice, runs like a charm on my laptop.
January 30, 2007 at 2:56 pm |
Sweet
February 26, 2007 at 8:12 pm |
I am curious about the artist/album of the background music. Can you tell us ?
April 16, 2007 at 7:58 pm |
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/
July 7, 2007 at 12:51 pm |
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.
August 10, 2007 at 3:22 pm |
[...] 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 [...]
August 22, 2007 at 1:04 am |
[...] 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 [...]
September 3, 2007 at 7:40 pm |
[...] 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 [...]
September 5, 2007 at 12:51 am |
[...] AS2 & AS3 Versions of the star test to compare AS2 to AS3 so you can judge for yourself [source] [...]
September 11, 2007 at 9:08 am |
[...] 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 [...]
September 11, 2007 at 5:16 pm |
[...] Вы можете посмотреть на рендер-тест, на работу AS 2 и AS 3 с пикселями. Это хороший тест, так как он наглядно демонстрирует, как AS 2 и AS 3 работают с пикселями, а значит и аналогично с видео. [...]
December 13, 2008 at 7:33 pm |
Thanks!,