gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / test / impl / others / ArrayVsArrayList.java @ 1965
History | View | Annotate | Download (2 KB)
1 |
package org.gvsig.raster.cache.buffer.impl.others; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
|
5 |
import org.gvsig.raster.cache.buffer.PxTile; |
6 |
import org.gvsig.raster.cache.buffer.impl.PxTileImpl; |
7 |
import org.gvsig.raster.cache.buffer.impl.rocache.ByteBand; |
8 |
import org.gvsig.raster.cache.buffer.impl.rocache.ReadOnlyCacheBand; |
9 |
|
10 |
/**
|
11 |
* This test compare the access time of an element in two cases. The first
|
12 |
* case is the access to an element in a simple array of objects. The second
|
13 |
* case is the access to an element in an ArrayList.
|
14 |
*
|
15 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
16 |
*
|
17 |
*/
|
18 |
public class ArrayVsArrayList { |
19 |
public static int N = 500000; |
20 |
/**
|
21 |
* @param args
|
22 |
*/
|
23 |
public static void main(String[] args) { |
24 |
ArrayVsArrayList p = new ArrayVsArrayList();
|
25 |
p.array(); |
26 |
p.arrayList(); |
27 |
} |
28 |
|
29 |
private void array() { |
30 |
long t1 = System.currentTimeMillis(); |
31 |
ArrayList<PxTile> stripeList = new ArrayList<PxTile>(); |
32 |
for (int i = 0; i < 1; i++) |
33 |
stripeList.add(new PxTileImpl(0, 0, 0, 0)); |
34 |
|
35 |
ReadOnlyCacheBand[] l = new ReadOnlyCacheBand[N]; |
36 |
for (int i = 0; i < N; i++) { |
37 |
ByteBand b = new ByteBand(stripeList, null, 15, 15, 15, 2345, 3244); |
38 |
l[i] = b; |
39 |
} |
40 |
int z = 0; |
41 |
for (int i = 0; i < N; i++) { |
42 |
int y = l[i].getBandNumber();
|
43 |
z += y; |
44 |
} |
45 |
long t2 = System.currentTimeMillis(); |
46 |
System.out.println("Time Array with " + N + " elements: " + (t2 - t1) + " milisegundos" + z); |
47 |
|
48 |
} |
49 |
|
50 |
private void arrayList() { |
51 |
long t1 = System.currentTimeMillis(); |
52 |
ArrayList<PxTile> stripeList = new ArrayList<PxTile>(); |
53 |
for (int i = 0; i < 1; i++) |
54 |
stripeList.add(new PxTileImpl(0, 0, 0, 0)); |
55 |
|
56 |
ArrayList<ReadOnlyCacheBand> l = new ArrayList<ReadOnlyCacheBand>(); |
57 |
for (int i = 0; i < N; i++) { |
58 |
ByteBand b = new ByteBand(stripeList, null, 15, 15, 15, 2345, 3244); |
59 |
l.add(b); |
60 |
} |
61 |
int z = 0; |
62 |
for (int i = 0; i < N; i++) { |
63 |
int y = l.get(i).getBandNumber();
|
64 |
z += y; |
65 |
} |
66 |
long t2 = System.currentTimeMillis(); |
67 |
System.out.println("Time ArrayList with " + N + " elements: " + (t2 - t1) + " milisegundos" + z); |
68 |
} |
69 |
|
70 |
} |