AS3 vs AS2 Performance

Hello,

I did some performance tests in AS2 and AS3 and what I found is really surprising.

I just wrote the below code in AS3 and similar code in AS2. But I don’t see ANY performance improvements in AS3 version. On a P4 3GHz HT, AS3 version takes 8% CPU and AS2 version also takes 7% CPU. No major difference.

So where is that 10x performance difference that people says for AS3/Flash Player 9.

Does this means that there is no difference in redrawing the screen in FP8 and FP9

AS3 Code:

var toggleX:Boolean = true;
root.addEventListener(Event.ENTER_FRAME, EnterFrameHandler);
function EnterFrameHandler(myEvent:Event)
{
for (var i:uint = 1; i <= 24; i++)
{
if (toggleX)
root[“Ball” + i].x += 5;
else
root[“Ball” + i].x -= 5;
}
toggleX = !toggleX;
}

AS2 Code:

var toggleX:Boolean = true;
_root.onEnterFrame = function()
{
for (var i:Number = 1; i <= 24; i++)
{
if (toggleX)
_root[“Ball” + i]._x += 5;
else
_root[“Ball” + i]._x -= 5;
}
toggleX = !toggleX;
}

For one, don’t post in multiple forums. Two, don’t use the task manager to compare performance. Three, the script you posted takes no time at all for the virtual machine of either player (8 or 9) to execute so it’s hard to tell which does better. Four:

AS3 (around 5ms):

var t:int = getTimer();
for(var i:int = 0; i < 1000000; i++) {
}
trace(getTimer() - t);

AS2 (around 2200ms):

var t:Number = getTimer();
for(var i:Number = 0; i < 1000000; i++) {
}
trace(getTimer() - t);

That’s not 10x, that’s 440x.

Thanks for your reply. Yes, I accept that there is difference in loops and Math calculations, but if there is difference then why it does not show up in Task Manager’s CPU usages ? And when things come for Repaint/Redrawing screen, it seems that there is NO difference. Neeraj

The task manager is so inaccurate for testing this sort of stuff it’s not even funny.

When it comes to rendering the screen, I’m pretty sure AS3 provides no performance benefit.

TheCanadian, thanks for your post.

Actually I am working on an application in flash which is performing slow. It is written in AS2. Issue is that it use to take high CPU and we can notice slowdown while using the application. On a core2duo system, it starts smoothly and tend to slow down as the number of movie clips on stage increase. After having 50-60 movie clips, we can notice slow down. All of those movie clips are moving along with a bezier path (their X/Y properties are updated in an onEnterFrame event on root).

We have tried many optimizations. Minimized the loops and double checked the variables etc. Also removed unused movie clips etc. Of course that gave positive results, but still CPU use and performance is not as expected. Therefore after searching over net, we decided to tried converting our application to AS3 as we read that its faster and have some performance improvement, but with our small tests, we figured that nothing changed in contrast to screen re-draw. So we need to figure how to tune the constantly redrawing movie clips. We have already tried cacheAsBitmap thing.

Neeraj.

You’re going to want to optimize your graphics by reducing vector points, alpha, gradient, etc. I’m not an expert on it but I bet there’s info on the web.

I always thought AS3 improved performance they were talking bout came to CPU usage.
I thought it was harder to slow down the computer with AS3 than AS2.
I haven’t gotten around to testing it yet, but AS3 works well with Papervision. I haven’t seen any slow down with it