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.
read the rest