Performance Comparison of common set types in flex

Source: Internet
Author: User
Test Method

PrivateFunctionTest ():Void

{

For(VaRJ: Int = 0; j <5; j ++)

{

Trace("Insert 10000 items ==============");

VaRT1: int, T2: int;

VaRI: Int = 0;

VaRA: array =NewArray ();

VaRAl: Arraycollection =NewArraycollection ();

VaRItem: string;

VaRV: vector. <string> =NewVector. <string> ();

T1 = gettimer ();

For(I = 0; I <10000; I ++)

A. Push (stringutil. newguid ());

T2 = gettimer ();

Trace("Array time consumption:/T", T2-t1 );

T1 = gettimer ();

For(I = 0; I <10000; I ++)

Al. additem (stringutil. newguid ());

T2 = gettimer ();

Trace("Arraycollection time:/t", T2-t1 );

T1 = gettimer ();

For(I = 0; I <10000; I ++)

V. Push (stringutil. newguid ());

T2 = gettimer ();

Trace("Vector time consumption:/T", T2-t1 );

Trace("");

Trace("Traverse 10000 items ==========");

T1 = gettimer ();

For(I = 0; I <10000; I ++)

Item = A [0];

T2 = gettimer ();

Trace("Array time consumption:/T", T2-t1 );

T1 = gettimer ();

For(I = 0; I <10000; I ++)

Item = al [0];

T2 = gettimer ();

Trace("Arraycollection time:/t", T2-t1 );

T1 = gettimer ();

For(I = 0; I <10000; I ++)

Item = V [0];

T2 = gettimer ();

Trace("Vector time consumption:/T", T2-t1 );

Trace("");

}

}

Test output

Insert 10000 items ==============

Array time used: 465

Arraycollection time consumption: 788

Vector time consumption: 444

 

Traverse 10000 items ============

Array time consumed: 2

Arraycollection time: 98

Vector time consumption: 2

 

Insert 10000 items ==============

Array time used: 433

Arraycollection time consumption: 791

Vector time consumption: 430

 

Traverse 10000 items ============

Array time consumed: 2

Arraycollection time: 97

Vector time consumption: 2

 

Insert 10000 items ==============

Array time used: 427

Arraycollection time consumption: 805

Vector time consumption: 415

 

Traverse 10000 items ============

Array time consumed: 1

Arraycollection time: 97

Vector time consumption: 1

 

Insert 10000 items ==============

Array time used: 422

Arraycollection time consumption: 824

Vector time consumption: 401

 

Traverse 10000 items ============

Array time consumed: 2

Arraycollection time: 97

Vector time consumption: 2

 

Insert 10000 items ==============

Array time used: 467

Arraycollection time consumption: 772

Vector time consumption: 438

 

Traverse 10000 items ============

Array time consumed: 2

Arraycollection time: 98

Vector time consumption: 2

Conclusion

Array and vector are similar in performance. When inserted, the vector is slightly faster and traversal is similar. The advantage of vector is strong type, and the disadvantage is that it requires Flash Player 10. Therefore, we recommend that you use array for data storage operations.

Arraycollection has the worst performance. The insertion time is twice slower than that of array, and the traversal speed is dozens of times slower. The advantages of arraycollection are interface Data Binding and support for advanced methods such as data sorting.

Original article: http://blog.csdn.net/hunkcai/article/details/6159516

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.