ActionScript 3.0 Draw Speed Test: Drawing Primitives Vs. Placing MovieClips

I got a comment about ActionScript 3 the other day which asked a simple and fair question (paraphrased as):

If you’re just using simple shapes like circles, is it faster to draw them to the stage with drawCircle, or to use MovieClips/Sprites to draw them?

Did I know the answer? Um, no… So I knocked up a quick bit of flash to find out. Before you’re given the answer, why not have a quick ponder about what you think will happen? I’ve got to admit, when I did this I got completely the wrong result! Ha! Shows what I know about anything…

Brief analysis plus source-code n’ file after the jump…

Well, who’d have thunk it?: Drawing is definitely quicker – but by how much? I’ve ran the test a bunch of times on (notoriously slow) 64-bit Linux Flash Plugin 10.0.42, and came in with numbers between 38% quicker and 125% quicker (i.e. drawing primitives can get the job done over twice as fast as placing MovieClips…). There really is quite a huge range in execution time, but drawing primitives is definitely the faster by far. Also, I showed the lovely wife what I’d spent a couple of hours yesterday doing, and when running on 64-bit Windows 7, results came back showing drawing to be over 400% faster, because the movie clip duration was over 1000 ticks! Shocking!

Typical Flash Speed Test Results on 64-bit Linux
Typical results on my 64-bit Linux rig: What numbers do you get?

I guess the MovieClip has the overhead of having a lot of other properties and things, and you have to take scaling into account… I’d originally thought that the drawn circles would be a little slower because you have to fill them in (which would mean you need to calc the area of the circle and go pixel by pixel), while the MovieClip might act more as stamp (which would mean adding the data to the screen by just dumping the bitmap data onto the stage), but I guess not…

It’s interesting to see that if you remove the MovieClip colour transforms, then drawing the circles is still significantly faster, as the colour transforms don’t take up a lot of CPU time at all…

Guess you learn something new every day! :D (Oh, and the whole Japanese motif is because while writing this I kept thinking about Banzai!).

Flash File Source Code:

The flash CS4 .fla file for the above can be found: here.

Leave a Reply

Your email address will not be published.