• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

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

LEGEND ,
Jun 11, 2010 Jun 11, 2010

Copy link to clipboard

Copied

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);

TOPICS
ActionScript

Views

5.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 11, 2010 Jun 11, 2010

Copy link to clipboard

Copied

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.totalMemory/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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 11, 2010 Jun 11, 2010

Copy link to clipboard

Copied

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 11, 2010 Jun 11, 2010

Copy link to clipboard

Copied

This is getting even more interesting because different methodologies show different results.

The one I did - all the instances were created within the same loop. kglad demonstrated that when there is a period of time between instantiations difference is really small.

Actually, when I was doing it first I also observed different results depending on when memory is read. I suspect that runtime environment re-allocates and manages memory constantly. I am not sure but it maybe that in some time after instance is created it is, so to speak, reprocessed again. Sort of there is notion (ghost) of instance left and it is partially dispersed... Spooky... Needa think bout it...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 11, 2010 Jun 11, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 11, 2010 Jun 11, 2010

Copy link to clipboard

Copied

Why do you think there is the difference between these two methods?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 11, 2010 Jun 11, 2010

Copy link to clipboard

Copied

All things equal, method call in the loop on 1000 iterations takes over 100 ms longer than pure loop.

My main concern is that the approach of calling method inside the loop is not as straightforward for this test purpose. I understand loop cannot be paused in its purest execution. Method might be vulnerable. This may mean that, for instances, if Flash decides to kick in extra processing it may be able to do so inside the method but not in the loop.

I checked time between iterations. Pure loop is smoother - average period between calls is 25% less than when method is called. Standard deviation is 122 for methods call and 91 for pure loop.

Again, if there is any kind of post processing and redistribution few milliseconds is plenty of time to do that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 11, 2010 Jun 11, 2010

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 11, 2010 Jun 11, 2010

Copy link to clipboard

Copied

Hey guys..

Now THAT was some real usefull info!

Nice!!!

Best regards

Peter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines