Vector of generic arrays in ActionScript3.0 (AS3)

Source: Internet
Author: User

Adobe officially does not have the term "generic array", which is my own term for vectors (a bit of a title party), but vector is actually somewhat similar to a generic array in C #.

Yang over the original banyan tree
Source: http://yjmyzz.cnblogs.com

We know that array arrays in ActionScript3.0 can hold multiple types, even in the same array of arrays, and can be stored in string,object,number ..., but in fact we are actually developing, Typically, the types of elements stored in an array are consistent, and to improve efficiency in this case, AS3.0 adds a new vector class.

It enforces that each element in the array must be of the same type, eliminating the "boxing", "unpacking" operations, and improving performance.

The following section of the test code shows the performance differences between vectors and array:

1 varcount:uint=50000;2 varv:vector.<string>=NewVector.<string> (count);//declaring methods for vector of generic arrays3 varastr:array=NewArray (count);4 varAobj:array =NewArray (count);5 vari:uint=0,j:uint=100;6 vart:string="";7  8 //Initialize9  for(i=0; i<count-1; i++) {Tenv[i]=math.random (). toString (); Oneastr[i]=V[i]; AAobj[i] = {"a": V[i]}; - } -   the //Start Test--vector - varStarttime=Gettimer (); - varElapsed:uint=0; -   +  while(j--) { -      for(i=0; i<count-1; i++) {       +t=typeofV[i]; A     } at } -Elapsed=gettimer ()-StartTime; - Trace (t); -Trace"vector<string> Time:", elapsed,"\ n"); -   - //start Test--array (String) inj=100; -Starttime=Gettimer (); to  while(j--) { +      for(i=0; i<count-1; i++) { -t=typeofAstr[i]; the     } * } $Elapsed=gettimer ()-StartTime;Panax Notoginseng Trace (t); -Trace"Array (String) Time-consuming:", elapsed,"\ n"); the   + //start Test--array (Object) Aj=100; theStarttime=Gettimer (); +  while(j--) { -      for(i=0; i<count-1; i++) { $t=typeofAobj[i]; $     } - } -Elapsed=gettimer ()-StartTime; the Trace (t); -Trace"Array (String) Time-consuming:", elapsed,"\ n");
View Code

Vector of generic arrays in ActionScript3.0 (AS3)

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.