Performance quirk
Shane McCartney, the author of http://www.lostinactionscript.com has a presentation here (page 88)
where he states that using
var var_1:String = "str 1", var_2:String = "str 2", var_3:String = "str 3";
is more efficient than
var var_1:String = "str 1";
var var_2:String = "str 2";
var var_3:String = "str 3";

but this source says the exact opposite.
10. One line assignments DO NOT buy any performance (true in other langs)

There were some other things that were contradictory between the two articles, but this is the one I decided to check.
so who's right, well it turns out (according to my test) that the single line is in fact faster, but I'm getting a 10% increase in declaring 4 variables, and not the 30% as expressed in the slides.

more importantly I figured out that the whitespace was making the difference. So once I put the statements in a line
var var_1:String = "str 1";var var_2:String = "str 2";var var_3:String = "str 3";
and put these inline with the for loop braces, the speed increase was over 10 fold. That's right more that 10x faster to have everything in a line (almost 20 depending on how it's formatted)

So I did some investigations, in disbelief of how brutal these numbers were. My first though was that I should change from compiling for flash 9 to compiling for flash 10. Seeing how that didn't fix anything I kept looking. Next I switched from debug mode to release mode. And there it was, once I switched to release that 10+ fold difference was gone. Flash develop (using the flex compiler) gives you the choice of compiling in release or debug mode, but I don't understand why this difference is so big. I remember reading that switching from debug mode to release mode gives you a performance increase, but this makes me ot want to use debug mode EVER.


another thing I noticed, when using this
            startTime = getTimer();
for (var i:int = 0; i < count; i++) {
var var_5:String = "str 1",
var_6:String = "str 1",
var_7:String = "str 1",
var_8:String = "str 1";
}
endTime = getTimer();
t1 = endTime - startTime;

startTime = getTimer();
for (var k:int = 0; k < count; k++) {
var var_1:String = "str 1",
var_2:String = "str 1",
var_3:String = "str 1",
var_4:String = "str 1";
}
endTime = getTimer();
t2 = endTime - startTime;


t2 is slower than t1
if I reverse the order, the time difference flips. Which means, that whatever executes first, executes faster.
As far as I can tell the loop functions are identical in what they do, so why is it that the fist one executes faster?
Posted on 2009 May 23 by Daniel

(optional)

smile wink wassat tongue laughing sad angry crying 


Enter the code shown in the image:


| Forget Me
Content Management Powered by CuteNews