gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / test / others / TestCacheVsMemory.java @ 1965
History | View | Annotate | Download (4.16 KB)
1 |
package org.gvsig.raster.cache.buffer.impl.others; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import junit.framework.TestCase; |
6 |
|
7 |
import org.gvsig.jgdal.GdalException; |
8 |
import org.gvsig.raster.cache.buffer.Buffer; |
9 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
10 |
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException; |
11 |
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl; |
12 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
13 |
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer; |
14 |
import org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.RasterCacheBuffer; |
15 |
|
16 |
/**
|
17 |
* Performance Test: It loads a complete image of 65MB in a cached buffer and after read the
|
18 |
* same image in a memory buffer. For this test we use a small size of cache (2MB) and a size of
|
19 |
* one page of 0.2MB
|
20 |
*
|
21 |
* REPEAT = 1
|
22 |
* Using setValues
|
23 |
* Time cached: 1538 ms
|
24 |
* Time memory: 1163 ms
|
25 |
*
|
26 |
* REPEAT = 1
|
27 |
* Using setLines
|
28 |
* Time cached: 198 ms
|
29 |
* Time memory: 171 ms
|
30 |
*
|
31 |
* REPEAT = 10
|
32 |
* Using setValues
|
33 |
* Time cached: 14317 ms
|
34 |
* Time memory: 11168 ms
|
35 |
*
|
36 |
* REPEAT = 10
|
37 |
* Using setLines
|
38 |
* Time cached: 1944 ms
|
39 |
* Time memory: 1209 ms
|
40 |
*
|
41 |
* Intel(R) Core(TM)2 CPU E8400 @ 3.00GHz
|
42 |
* 2GB RAM DDR3 1066
|
43 |
* HDD ATA 133
|
44 |
* Linux Ubuntu 10.04 kernel 2.6.24
|
45 |
*
|
46 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
47 |
*/
|
48 |
public class TestCacheVsMemory extends TestCase { |
49 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
50 |
private static int REPEAT = 10; |
51 |
|
52 |
public void start() { |
53 |
this.setUp();
|
54 |
this.testStack();
|
55 |
} |
56 |
|
57 |
public void setUp() { |
58 |
System.err.println("CacheVsMemory running..."); |
59 |
} |
60 |
|
61 |
public void testStack() { |
62 |
|
63 |
try {
|
64 |
GdalRead input = null;
|
65 |
//Read input data
|
66 |
input = new GdalRead(rasterIn);
|
67 |
Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight()); |
68 |
|
69 |
|
70 |
//Reducimos el tama?o de la cache para una prueba con menos datos
|
71 |
BufferCacheManagerImpl.cacheSize = 25;
|
72 |
BufferCacheManagerImpl.pageSize = 2;
|
73 |
|
74 |
//****************CACHE**********************
|
75 |
long t1 = System.currentTimeMillis(); |
76 |
for (int iTimes = 0; iTimes < REPEAT; iTimes++) { |
77 |
|
78 |
//Create Buffer
|
79 |
Buffer buf1 = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
80 |
input.getWidth(), |
81 |
input.getHeight(), |
82 |
input.getBandCount()); |
83 |
|
84 |
//Set data to buffer
|
85 |
setValues(dataIn, buf1); |
86 |
buf1.free(); |
87 |
} |
88 |
|
89 |
long t2 = System.currentTimeMillis(); |
90 |
System.out.println("Tiempo StripeCache : " + (t2 - t1) + " milisegundos"); |
91 |
//****************FIN CACHE******************
|
92 |
|
93 |
//****************MEMO***********************
|
94 |
t1 = System.currentTimeMillis();
|
95 |
for (int iTimes = 0; iTimes < REPEAT; iTimes++) { |
96 |
|
97 |
//Create Buffer
|
98 |
Buffer buf2 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
99 |
input.getWidth(), |
100 |
input.getHeight(), |
101 |
input.getBandCount(), |
102 |
true);
|
103 |
|
104 |
//Set data to buffer
|
105 |
setValues(dataIn, buf2); |
106 |
buf2.free(); |
107 |
} |
108 |
|
109 |
t2 = System.currentTimeMillis();
|
110 |
System.out.println("Tiempo Memoria : " + (t2 - t1) + " milisegundos"); |
111 |
//****************FIN MEMO******************
|
112 |
|
113 |
input.close(); |
114 |
} catch (GdalException e) {
|
115 |
e.printStackTrace(); |
116 |
} catch (IOException e) { |
117 |
e.printStackTrace(); |
118 |
} catch (ProcessInterruptedException e) {
|
119 |
e.printStackTrace(); |
120 |
} catch (OperationNotSupportedException e) { |
121 |
e.printStackTrace(); |
122 |
} |
123 |
|
124 |
|
125 |
} |
126 |
|
127 |
public void setValues(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
128 |
if(dataIn instanceof byte[][][]) { |
129 |
byte[][][] d = (byte[][][])dataIn; |
130 |
for (int band = 0; band < d.length; band++) { |
131 |
for (int row = 0; row < d[band].length; row++) { |
132 |
for (int col = 0; col < d[band][row].length; col++) { |
133 |
buf.setElem(row, col, band, (byte)d[band][row][col]);
|
134 |
} |
135 |
} |
136 |
} |
137 |
} |
138 |
} |
139 |
|
140 |
public void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
141 |
if(dataIn instanceof byte[][][]) { |
142 |
byte[][][] d = (byte[][][])dataIn; |
143 |
for (int iBand = 0; iBand < d.length; iBand++) { |
144 |
for (int row = 0; row < d[iBand].length; row++) { |
145 |
buf.setLineInBandByte(d[iBand][row], row, iBand); |
146 |
} |
147 |
} |
148 |
} |
149 |
} |
150 |
|
151 |
} |