Fool's Raving AS3 notes: For All in

Source: Internet
Author: User
Tags array length
Notes

The new for Each ... In addition to traversing XML, can also be used to traverse arrays and objects. Create "Million Xiong":

var testarr:array = new Array ();
for (var i:number = 0; i < 1000000; i++)
{
Testarr.push (i);
}

Previous for and for ... in and new for Each ... in loop:

For 260 milliseconds
var len:number = testarr.length;
for (var j:number = 0; J < Len; j + +)
{
testarr[j]++;
}
For ... in 8000 milliseconds
for (Var k:string in Testarr)
{
testarr[k]++;
}
For each ... in 58 milliseconds
For each (Var m:number in Testarr)
{
m++;
}

What about efficiency? After several tests, the for loop averaged 260 milliseconds (an average of 400 milliseconds without an array length), the for ... in loop averaged 8000 milliseconds, for each ... in loop 58 milliseconds!! So you should try to avoid for ... in, use for each ... in, with a for loop the best stored array length (var len:number = testarr.length;).

The case of object, for ... in an average of 560 milliseconds, for each ... in an average of 8 milliseconds.

var testobj:object = new Object ();
for (var i:number = 0; i < 100000; i++)
{
Testobj[i] = i + 1;
}
For ... in Read tab 560 MS
for (Var j:string in testobj)
{
testobj[j]++;
}
For each ... in direct read value 8 milliseconds
For each (Var k:number in testobj)
{
k++;
}

Small series of words: Or that sentence, we are not everyone can understand the flex so, but each of us can do a little bit of interest for our efforts. As long as your one click, a message can give the author more power. International...... Collective to fool the nest of the words of irrigation.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.