nemoblog

Author Archive

expensive function calls

by on Jan.03, 2010, under flash performance

While optimizing  an implementation of the shadow cast algorithm, I realised that function calls are really expensive in terms of performance. Look at this small example:

private var _iterations:int = 1000000;

private function startTest():void {
 var inlineStartTime:int = getTimer();
 for (var i:int = 0; i < _iterations; ++i) {
 10 + 10; // just to use CPU time
 }
 trace("Inline  : " + (getTimer() - inlineStartTime));
 
 var externalStartTime:int = getTimer();
 for (var j:int = 0; j < _iterations; ++j) {
 doSomething();
 }
 trace("External: " + (getTimer() - externalStartTime));
}

private function doSomething():void {
 10 + 10;
}

That comes to this result:

Inline: 94
External: 382

Thus, simple functions should be avoided in loops with many iterations if possible. Inline the statements instead.

Leave a Comment :, , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...

    Archives

    All entries, chronologically...