- PerformanceTimer timer=new PerformanceTimer();
- timer.start();
- final int n=10000;
- List<String> alist=new ArrayList<String>(n);
- for (int i=0; i<n; i++) {
- alist.add("asd");
- }
- timer.getValue("ArrayList " +n+" items took ");
- timer.start();
- List<String> blist=new LinkedList<String>();
- for (int i=0; i<n; i++) {
- blist.add("asd");
- }
- timer.getValue("LinkedList " +n+" items took ");
- timer.start();
- String[] clist=new String[n];
- for (int i=0; i<n; i++) {
- clist[i]="asd";
- }
- timer.getValue("Array " +n+" items took ");
- //eredmények
- 12-30 10:17:20.433: E/PerformanceTimer(2069): 3 ms : ArrayList 1000 items took
- 12-30 10:17:20.433: E/PerformanceTimer(2069): 1 ms : LinkedList 1000 items took
- 12-30 10:17:20.433: E/PerformanceTimer(2069): 0 ms : Array 1000 items took
- 12-30 10:16:29.683: E/PerformanceTimer(1999): 2 ms : ArrayList 10000 items took
- 12-30 10:16:29.703: E/PerformanceTimer(1999): 19 ms : LinkedList 10000 items took
- 12-30 10:16:29.707: E/PerformanceTimer(1999): 0 ms : Array 10000 items took
- 12-30 10:17:54.152: E/PerformanceTimer(2106): 34 ms : ArrayList 100000 items took
- 12-30 10:17:54.437: E/PerformanceTimer(2106): 286 ms : LinkedList 100000 items took
- 12-30 10:17:54.507: E/PerformanceTimer(2106): 66 ms : Array 100000 items took
ArrayList, LinkedList vagy a sima Array a gyorsabb?
Végeredményben:
nagyon randomak az eredmények:
összeségében nagyobb elemszámokra a fixed ArrayList teljesít jobban, utána jön az Array
kisebb elemszámokra általában az Array gyorsabb bár néha az ArrayList kerekedik sebességben felül.