Performance comparison of arrays, list<>, ArrayList

Source: Internet
Author: User

Tag:list<t>    performance     array    

Static void main (String[] args) {    stopwatch sw = new  Stopwatch ();    int[] intarray = new int[100];     Sw. Start ();    for  (int i = 0; i < 100; i++)      {        intArray[i] = i;   &NBSP;&NBSP;}&NBSP;&NBSP;&NBSP;&NBSP;SW. Stop ();     console.writeline (" Add 0 ~ 100 to int[100]  :  "&NBSP;+&NBSP;SW. Elapsed);     arraylist list = new arraylist ();     Sw = new stopwatch ();     sw. Start ();    for  (int i = 0; i < 100; i++)      {        list. ADD (i);     }&NBSP;&NBSP;&NBSP;&NBSP;SW. Stop ();     console.writeline (" add 0 ~ 100 to arraylist  :  "&NBSP;+&NBSP;SW. Elapsed);    list<int> intlist = new list<int> ();     sw = new stopwatch ();     sw. Start ();    for  (int i = 0; i < 100; i++)      {        intlist.add (i);     } &NBSP;&NBSP;&NBSP;&NBSP;SW. Stop ();     console.writeline (" add 0 ~ 100 to list<int > :  "&NBSP;+&NBSP;SW. Elapsed);     console.readline ();}

Effect

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/82/7E/wKiom1dW0euBFoGtAAANEDjci8g851.png "title=" 2016-06-07_215309.png "alt=" Wkiom1dw0eubfogtaaanedjci8g851.png "/>

You can see that the array is significantly faster, but must initialize the length


Visual reason is that a boxing operation occurred when adding elements to the ArrayList

This article is from the "lybing" blog, make sure to keep this source http://lybing.blog.51cto.com/3286625/1787125

Performance comparison of arrays, list<>, ArrayList

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.