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