Skip navigation
Currently Being Moderated

Memory Benchmark Test :: MovieClip vs. Sprite vs. Shape

Jun 11, 2010 12:51 PM

I performed a benchmark test memory consumption by three DisplayObjects - MovieClip, Sprite, and Shape.

 

Below are results and method used.

 

I just wanted to create instances. Test with adding instnaces to display list showed a slight difference in terms of memory consumption.

 

Observations:

 

Sprite uses from 16 to 22% with average 18% less memory than MoviClip.

 

Shape uses from 42 to 55% with average of 46% less memory than MovieClip.

 

Shape uses from 32 to 42% with average of 35% less memory than Sprite.

 

Results. Numbers in the first row are loop iteration values. Columns show bites consumed by objects and fraction of differences as compared to MovieClip performance.

 

 

50vs MC100vs MC1000vs MC5000vs MC10000vs MC50000vs MCAvg%
MovieClip36864696326144003137536622592031121408
Sprite286720.22532480.245120000.1726501120.1652551680.16262594560.160.19
Shape163840.56368640.473358720.4517612800.4435676160.43173588480.440.47
Shape vs Sprite0.430.310.340.340.320.340.35

 

Code:

 

var tf:TextField = new TextField();
addChild(tf);
var mem:uint = 0;
var i:int = 0;
var arr:Array = [];
var numIterations:int = 1000;
mem = System.totalMemory;
for (i = 0; i < numIterations; i++) 
{
     arr.push(new MovieClip());
}
tf.text = "m " + numIterations + " - " + String(System.totalMemory - mem);
 
Replies
  • kglad
    72,340 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 11, 2010 1:22 PM   in reply to Andrei1

    here's another test under more realistic conditions that shows no significant difference between movieclip memory and shape memory:

     

    //////////////////////////////////

    var rad:int = 1;

    var rct:Shape = new Shape();
    rct.graphics.beginFill(0xff0000);
    rct.graphics.drawRect(0, 0, 100, 100);
    addChild(rct);
    rct.x = stage.stageWidth * .5 - 50;
    rct.y = stage.stageHeight * .5 - 50;

    var container:Sprite = new Sprite();
    container.x = stage.stageWidth * .5;
    container.y = stage.stageHeight * .5;
    addChild(container);

    var sTimer:Timer = new Timer(10, 501);
    sTimer.addEventListener(TimerEvent.TIMER, onTick);
    sTimer.start();

     


    function onTick(event:TimerEvent):void {
         var s:MovieClip = new MovieClip()
         //var s:Shape = new Shape();
         s.cacheAsBitmap = true;
         s.graphics.beginFill(0x000000, 1/255);
         s.graphics.drawCircle(rad, rad, rad);
         s.x = s.y = -rad;
         container.addChild(s);
        
         if (rad%100==1) {
              trace(rad,Math.round(System.privateMemory/1024),Math.round(System.tot alMemory/1024))
         }
         rad ++;
    }

    /////////////////////////////////

     

     

     

    shape:

     

    1    299376 32356
    101 299388 40272
    201 299388 77332
    301 396980 180136
    401 592848 376004
    501 917356 697616

     

    movieclip:

     

    1    299924 32356
    101 298384 40204
    201 298384 78360
    301 395376 179500
    401 590748 374868
    501 914668 695788

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2010 2:01 PM   in reply to Andrei1

    Hey guys..

     

    Now THAT was some real usefull info!

     

    Nice!!!

     

    Best regards

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2010 2:28 PM   in reply to kglad

    Wouldn't there be a processing overhead too? It would also be small of course, but as MovieClips have more properties there would be more things to be checked especially when adding to the display list...

     
    |
    Mark as:
  • kglad
    72,340 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 11, 2010 2:56 PM   in reply to Andrei1

    it's not a time difference.  here are the results using a for-loop instead of a timer loop:

     

    movieclip:

     

    1 224080 23768
    101 224080 24144
    201 224080 24512
    301 224080 24876
    401 224080 25232
    501 224080 25600

     

    shape:

     

    1 262520 23832
    101 262520 24192
    201 262520 24540
    301 262520 24884
    401 262520 25220
    501 262520 25568

     

    shape:

     

    1 264624 23868
    101 264624 24228
    201 264624 24576
    301 264624 24920
    401 264624 25256
    501 264624 25604

     

    movieclip:

     

    1 263656 23872
    101 263656 24248
    201 263656 24616
    301 263656 24980
    401 263656 25336
    501 263656 25704

     
    |
    Mark as:
  • kglad
    72,340 posts
    Jul 21, 2002
    Currently Being Moderated
    Jun 11, 2010 5:03 PM   in reply to Andrei1

    well, there are all sorts of things going on in the counter-point code i showed (which is your code).

     

    my point is only that in real-world apps, there's no significant difference in memory utilization between the various display objects.  i suspect all the other things going on in that code overwhelms any difference beween the displayobjects.

     

    and that's the way it always seems when i check a real app:  there's no memory benefit to using less flexible display objects than movieclips.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points