Actionscript 2 vs Actionscript 3 - A practical comparison.

YinYangTest Source Files

For alot of budding Flash game developers, our times bring with them a choice: AS3 - To switch or not to switch.

For those who are learning from scratch, the choice is obvious, you should definitely learn AS3 to begin with, AS2 is old hat, archeic, “Grandpa’s Actionscript”. Ok, well it’s probaly not referred to as that last one anyhow. However those, like myself, who “Grew up” on AS2 may feel a fond affection for it’s warm, snuggly,forgiving style. AS2 will let you off with a whole load of corner cutting, if you don’t mind the odd messy segment of code or a slight performance decrease. I currently have three games in the pipes, one of them is AS2, the other two are AS3, and switching between them (I like variation in the projects I’m working on) can be a bit brain frazzling at times, and for what gain? I set out, in a spare half hour, to test the practical benefit of coding in AS3 over AS2, and will let you decide for yourself if you think it’s worth it.

The files attached to this post are the source files I have used for this test. They are both self contained with no external class declarations for ease of distribution. Both are coded to generate 4000 “particles” of a YinYang design consisting of 21 curves (So while not overly complicated, it gives a much fairer comparison to everyday usage than the many Bitmap data particle systems you can find on google that show AS3 as performing 10-15 times faster than AS2)

Once 4000 YinYang particles have been generated, the amount of time it took to do this is traced in the output box in milliseconds. I have chosen the method of controlling the particles by a set of three Arrays for 2 reasons. 1. It allows me to keep the actual code used 99 percent Identical in both the AS2 and AS3 versions and 2. Array Manipulation is very heavy on the performance of Flash. So with this experiment we shall see the results of a PRACTICAL (i.e. similar to conditions one would use while actually making a game) comparison between AS2 performance and AS3 performance. Not only is there heavy strain on loops to account for code processing, but an awful lot of screen redrawing at a practical 25fps.

Here are my own personal results (which may differ from yours depending on what machine/plugin you use to play the file)

Computer Specs:

Intel Core Duo 1.66 GHZ

2GB DDR2 RAM

Geforce Go 7600.

Results:

Actionscript 2 Average over 10 trials to generate 4000 particles: 18890 Milliseconds

Actionscript 3 Average over 10 trials to generate 4000 particles: 8344 Milliseconds

The conclusion is, as expected, the AS3 version was faster than the AS2 version, but only just over twice as fast. This indeed does present a necessity to upgrade to keep up with the ever increasing complexity of current Flash games, and the benefits of a few new features, but, in my opinion, a practical speed advantage of just over 2 is far from the promise of Adobes virtual machine speed revolution. It seems the promised 10 times increase in performance was only meant for those entertaining blogs which showcase the authors experiments in Flash, which, valid as they are, do not apply to practical Flash Game Development.

So do I recommend the upgrade to AS3? It depends. If you are still using a version of Flash which doesn’t support it, then I’d say for now that there truly is no rush to throw money at Adobe for an upgrade to AS3 (via a Flash CS3 purchase) However, if you’re dragging your feet for comforts sake, throw yourself in head first and try something new. Just keep in mind, will your game be running faster at the compromise of cut features due to inexperience in the vastly different AS3? If so, it bears well to remember, that a faster codebase does not equate to a better game.

Thanks for reading this hefty post, I’m sorry if you felt it was rather drawn out, but I think it’s an issue which has only been really addressed by the Flash Experiment community, not the Game Development Community.

26 Comments so far

  1. SecretSecretary on January 26th, 2008

    Very interesting read indeed, something I have been contemplating about as well.

    I am no actionscript genius, but am very comfortable with AS2 and at the moment my version of Flash (Flash Mx, still Macromedia) does not support AS3.

    I did think AS3 would improve speed a lot more than just a bit over twice, but still, it does make a difference. Not enough to make me go out and spend a lot of money on Flash CS3, because the learning curve for AS3 is very daunting. What would make me go out and buy the newest flash is just because my version is so outdated. And then I would probably end up learning AS3 just to keep up with the times. Now I just need to save up, and that’s the hard part. Im poor as hell!

    Very informative read as well, thanks. :)

  2. Carlie on January 26th, 2008

    A practical and neutral approach, very nice :)

  3. Chris Ignatov on January 27th, 2008

    Well I can`t open those files since you don`t pay me to buy CS3, but I`ve seen it and it works great.Hoozah for Tony.

  4. Matt on January 28th, 2008

    Can I just note that the graphics card in your machine is irrelevant as flash doesnt use the graphics card to render it’s graphics (which is why it’s so slow!).

    Cheers

  5. SFB Tom on January 28th, 2008

    Oh dear, I think you have the wrong idea as to what Adobe means by increasing the speed of the code.

    Because you’re using code on the enter frame event, all your code can do is fill the space between frame events. If the code takes longer than the time between frame events, you’ll notice a slowdown. However, if you don’t take longer than the frame time, you won’t notice any time difference between nearly filling that time or just taking a fraction of a millisecond.

    If you look at the data you pulled from the experiment, compared to the expected result, you’ll actually see that AS3 is VERY much faster than AS2.

    At the frame-rate of 25fps, with 20 increments per frame, running up to 4000 increments, assuming flash renders each frame exactly on time (it doesn’t though) the test should take exactly 8000ms. Any extra time is the time its taking to run your code on each frame.

    Therefore: AS2 = 10890ms extra, and AS3 = 344ms extra. That means in this case, AS3 is over 30 times faster than AS2!

    Tom-

  6. SFB Tom on January 28th, 2008

    Also, just did a quick test, because the flash frame-rate is anything but perfect, and what should be exactly 8000ms to run (ie empty code called each frame at the same fps etc) actually takes an average of 8330ms (both AS2 and AS3)

    That means that our revised values are 10560ms and 14ms, meaning AS3 is a staggering 750 times faster!

    Yay for AS3 ^_^

    Tom-

  7. Tony on January 28th, 2008

    You have permission to make note of that.

  8. Glaiel Gamer on January 28th, 2008

    You also seem to mistake code speed with rendering speed. Flash Player 9 did almost nothing to increase the speed of rendering vector graphics (maybe a 1.5x increase in speed there, but it’s still lousy).

    The majority of the time you spend generating the yingyangs is spent rendering the vector graphics inside of them. Which is NOT an issue of AS3, it’s an issue of FP9 and CS3.

    If you do a graphicless, movieclipless test of say, pushing instances of a custom class into an array, with no graphical display, AS3 will have a HUGE increase in speed over AS2 (which is why the bitmap data particle effects are really fast, there’s no vector rendering).

    What does this mean? AS3 won’t improve graphics (unless you take advantage of the speed to do bitmap effects), however it WILL let you increase the intensity of behind-the-scene code such as AI and collision detections. You can do tons of large for loops for collisions, and controlling, and bullets, and particles (which should be bitmap rendered for optimal performance), and whatever other intense code you’re using.

    I originally tried making my new preloader with movieclips instead of a bitmap. It crashed flash before it even got done creating them. Bitmaps made the thing run at 15 FPS (that’s 100×100 = 10000 particles to deal with, including the math behind the movement. Even calling sqrt for each particle still made it run fast. That’s the true power of AS3)

  9. Tony on January 29th, 2008

    Eeep, I see exactly what you both are saying, with regards to framerate, and I’m afraid I didnt make myself very clear at all, In fact, the way I’ve put it (and it was very late at night, so please forgive) leads in compeltely the opposite way I intended. I posted my CPU specs but forot to state why, Its at 4000 yinyangs at 50 per frame that AS3 starts to lag on my machine, and once it starts to lag, you lack any previous benefit over avoiding lag on the slower AS2 codebase. You’re both certainly right there. As for the redrawing of the vector graphics Glaiel, thats the point, if AS3 doesnt increase the speed they can actually be displayed out, you lose out on any advantage to faster code anyway. But on the main points, you’re both right, the article does skim over many points that greatly affect performance.

  10. HeroInteractive on January 29th, 2008

    Great post and I’m loving the really great comments on here. I dare say, it was worthwhile just to read through all the comments.

    The huge question named above has been the plaguing my mind for months now. To switch or not to switch…

    I think one of the biggest factors for me, is not even performance related. For me, it’s more business related.

    Many of the sites out there right now that have API’s have not made the leap to AS3. Some of those sites are big on licensing. If you can’t connect to their required api, you can’t get the license. Until the times catch up with the industry as whole, I don’t think I’ll be making the leap just yet.

  11. Glaiel Gamer on January 29th, 2008

    But see, the vector renderer is not an issue of AS3. It’s an issue of the flash player version. A future flash player could drastically increase the rendering speed without the need to recompile the SWF.

    Anyway your topic title should have been more along the lines of “Flash Player 8 vs. Flash Player 9″

    AS3 is only one element of the equation you know? It’s extremely fast compared to AS2, much over 15 times faster if you code right. If you do a lot of optimizations, you can make it 30-50 times faster.

    Your title though, “Actionscript 2 Vs Actionscript 3 - A Practical Comparison.” suggests that you’re comparing just the actionscript component of CS3 builds vs. flash 8 builds.

    And also, you say in your response, “As for the redrawing of the vector graphics Glaiel, thats the point, if AS3 doesnt increase the speed they can actually be displayed out, you lose out on any advantage to faster code anyway.”

    This is a good point. However, you underestimate the behind the scene stuff that can go on.

    We know it has trouble with 4000 ying yangs, so lets say that that’s 4000 loops of code to run through. Let’s say that AS3 does the code without lag, but lags in the rendering, and that AS2 has trouble with both. It only feels like a 2x speed increase because it still spends the same time rendering.

    So try this situation then. 200 circles of various sizes, each checking collisions against each other circle. We can agree that the rendering time should be significantly lower than that of the 4000 ying yangs, and for extra support lets add cacheasbitmap onto them. There, a lag free rendering of 200 sprites. In AS2 this simulation, however will lag tremendously, and in AS3 it will still run at full speed, even without optimizations such as kdtrees or bsptrees or quadtrees.

    200 objects checking against each other is 200*200/2 loops of code. That’s 20000 loops of code. A significant INCREASE in code over the 4000 loop ying yang test.

    With this test, if you time it, I’m willing to bet that AS3 will show it’s 10-15x faster property. I recommend you try it, as I am far to lazy at the moment.

    In your practical test, all you did was create a crapload of particles. In practice, a game is much more than that. There is motion in the sprites, and interactions between sprites, and user input, and sound effect managing and a whole other side that is all code related. This is where AS3 shines, and simple speed tests can’t show that.

  12. John on January 29th, 2008

    Oh you guys.

  13. Matt on February 2nd, 2008

    Quiet Glaiel

    :)

  14. Tony on February 10th, 2008

    Wait, was that an AshkinShcrip Three Point Oh Challenge?

  15. Anne on February 19th, 2008

    Very Nice! Thanks!

  16. qgwflsok on March 2nd, 2008

    UAPLhk mfqjebuqqiml, [url=http://bgqmymgriioh.com/]bgqmymgriioh[/url], [link=http://kpcwjohxxrzp.com/]kpcwjohxxrzp[/link], http://qqluaqmyjfbx.com/

  17. Nathan on July 28th, 2008

    Your post generated a lot of insightful discussion. Thanks!

  18. mark on January 11th, 2009

    i changed your graphic symbol to mc and checked box to cache as bitmap that improved performance both cpu and run time
    as3 from 9562 to 8000
    as2 from 28562 to 24343
    before cache as bitmap as3 vs as2 =as3 X 2.98 faster
    after bitmap as3 vs as2 = as3 X 3.04 faster
    in big app it can make big diff.
    tnx alot for that example

    it gave me alot of motivation to continue developing games with as3 although it does request more time to spend on programming ;)

  19. Magicpt on January 14th, 2009

    Good Post guys, awesome discussion! made my head a bit clear. ty

  20. andre on January 21st, 2009

    And interesting math as well:
    “Therefore: AS2 = 10890ms extra, and AS3 = 344ms extra. That means in this case, AS3 is over 30 times faster than AS2!
    Tom”
    So if we reduce the framerate so that AS3 could cope with the code within the frame time without extra time, i.e. extra=0, then AS3 will be indefinitely faster than AS2. A good selling point for AS3.

  21. Ted on January 22nd, 2009

    A very good read for a new guy like me.
    But I have a question.
    My question concerns the actual code used for AS2 vs AS3. I have access to AS2 tutorials, but the company just bought Flash CS4. Will the AS2 tutorial videos help me learn AS3 or just make AS3 harder because I learned AS2 code?
    Thanks,

  22. Aryo Handono on February 1st, 2009

    Please note,
    If you have a flash project involving webservices (ASP.NET or Java), please think twice before migrating to AS3. There is no built-in library/class for webservices in AS3, unless you include custom package.

  23. cpen on March 12th, 2009

    Thanks for the awesome post and the code, This was exactly what I was looking for!

  24. Michael Awesome on July 28th, 2009

    What an excellent discussion, thanks guys!

  25. Филипп on August 17th, 2009

    Даа… :) Вы бы знали что про Вас пишут в других блогах :)

  26. JNTT on October 9th, 2009

    Hi man,

    That was a very cool example ur a genius man!!
    Rgds
    JNTT

Leave a reply