Cycle Variable Declaration Performance in ActionScript 3

Despite all the well-known blogs about this problem, I always doubt some of the results, and my personal tests show that the well-known standard is not the best.

Declaring variables inside a loop so that they are close to its size and speed up its access to this method, but allocating more memory or declaring out of scope for , to preserve memory allocation, but increase processing for iteration in a remote instance.

My results show that method B is faster (sometimes), I want to know the background around this.

results

change, and they are not a guru pavers.

And what do you guys think about this?

Method a

var object:Object = new Object();
var loop:int = 100000
for (var i:int = 0; i < loop; i++)
{
    object = new Object();
    object.foo = foo;
    object.bar = bar;
}

OR

Method B

var loop:int = 100000
for (var i:int = 0; i < loop; i++)
{
    var object:Object = new Object()
    object.foo = foo;
    object.bar = bar;
}
+5
source
2

TL;DR; .

, object. ActionScript, JavaScript, "". , var - . C Java, (, , ).

AS . , . ( " var " , , , .)

. Script 3.0: , , Scope:

- , ... ActionScript 3.0 , .

.

+8

AS3 , . - . B :

var loop:int = 100000;
var i:int;
var object:Object;
for (i = 0; i < loop; i++) {
    object = new Object();
    object.foo = foo;
    object.bar = bar;
}

, , . . , :

trace(a);
var a:int = 10;
trace(a);

. , :

var a:int;
trace(a);
a = 10;
trace(a);

, :

for (var i:int = 0; i < m; i++) {

}
for (var i:int = 0; i < n; i++) { // i is already declared once

}

AS3, JS C, ++, Java ..

+10

All Articles