1 Reply Latest reply on Jul 2, 2008 10:23 AM by Rothrock

    AS3 vs AS2 Performance

    nkhajanchi
      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:
      Quote:
      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:
      Quote:
      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;
      }


      AS3 Code:
      [QUOTE]
      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;
      }
      [/QUOTE]

      AS2 Code:
      [QUOTE]
      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;
      }
      [/QUOTE]

      Neeraj
        • 1. Re: AS3 vs AS2 Performance
          Rothrock Level 5
          Well I'm not sure that your code really gets to the heart of matters, but there are several things that are probably mudding the waters.

          First, the improvements in many ways are in speed, not CPU usage. So you won't necessarily see that drop.

          Next if I wanted to test the differences I would use a lot more than 24 display objects. Perhaps 240 or 2400 and then use some kind of frame rate calculator to see what kind of rates you get.

          The next thing to check is which version of the plug-in you are publishing for. I found that even AS2 code published for the Flash 9 player often performs better than AS2 code published for 8.

          I have found AS3/Flash 9 to be much faster when having to do a lot of math. And (not that I understand it yet) the complete redesign of the display list does make certain things much faster.