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