Test the efficiency of the array push and Unshift methods

Source: Internet
Author: User

Paste the code first, then fill in the content.
<!DOCTYPE HTML><HTML>    <Head>        <title>Test the efficiency of the array push and Unshift methods</title>    </Head>        <Body>    </Body>        <Scripttype= "Text/javascript">            varStartTime= 0; /*Start Time*/            varEndTime= 0; /*End Time*/            vararr= []; /*Test Array*/            varN= 50000; /*Number of Inserts*/            varI= 0; /*Cyclic cardinality*/Calculate ("Unshift"); /*Calculate method Test*/Calculate ("Push"); /*Push Method Test*/                        functionCalculate (method) {i=0; Arr= [];  while(i!=N) {                    if(i==0) {StartTime= NewDate (); /*Start Time Acquisition*/} Arr[method] (i); I++;                }; EndTime= NewDate (); /*End Time Get*/Console.log (Method+" : "+(Endtime.gettime ()-starttime.gettime ())+"milliseconds"); /*Time Difference*/            }    </Script></HTML>

Test the efficiency of the array push and Unshift methods

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.