New for each... Besides traversing XML, in can also be used to traverse arrays and objects. Create "millions of troops ":
VaR testarr: array = new array ();
For (var I: Number = 0; I <1000000; I ++)
{
Testarr. Push (I );
}
Previous for and... In and the new for each... In loop:
// For 260 milliseconds
VaR Len: Number = testarr. length;
For (var j: Number = 0; j <Len; j ++)
{
Testarr [J] ++;
}
//... In 8000 milliseconds
For (var k: String in testarr)
{
Testarr [k] ++;
}
// For each... In 58 Ms
For each (var m: Number in testarr)
{
M ++;
}
How efficient is it? After multiple tests, the average length of the For Loop is 260 milliseconds (the average length of the non-Pre-stored array is 400 milliseconds),... The average in cycle is 8000 milliseconds, for each... In loop 58 Ms !! So try to avoid... In, for each... In, if you use a for loop, it is best to prestore the array length (VAR Len: Number = testarr. length ;).
Object,... Average in 560 ms, for each... The average in time is 8 ms.
VaR testobj: Object = new object ();
For (var I: Number = 0; I <100000; I ++)
{
Testobj [I] = I + 1;
}
//... In reads tags in 560 milliseconds
For (var j: String in testobj)
{
Testobj [J] ++;
}
// For each... In direct read value: 8 ms
For each (var k: Number in testobj)
{
K ++;
} From http://www.jinflex.com/index.php/archives/91