Statistics
| Revision:

gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / src / test / java / org / gvsig / raster / cache / buffer / impl / stripecache / horizontal / TestCachePerformance.java @ 991

History | View | Annotate | Download (2.7 KB)

1
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal;
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.impl.BufferCacheManagerImpl;
11
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
12

    
13
/**
14
 * Performance Test
15
 * Time 9.3 - 10 seg 
16
 * REPEAT = 10
17
 * Intel(R) Core(TM)2 CPU E8400  @ 3.00GHz
18
 * 2GB RAM DDR3 1066
19
 * HDD ATA 133
20
 * Linux Ubuntu 8.04 kernel 2.6.24
21
 * 
22
 * @author Nacho Brodin (nachobrodin@gmail.com)
23
 */
24
public class TestCachePerformance extends TestCase {
25
        private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
26
        private static int REPEAT = 10;
27
        public int aux = 0;
28
        
29
        public void start() {
30
                this.setUp();
31
                this.testStack();
32
        }
33

    
34
        public void setUp() {
35
                System.err.println("StripeCache TestCachePerformance running...");
36
        }
37
        
38
        public void testStack() {
39
                long t1 = System.currentTimeMillis();
40
                GdalRead input = null;
41
                try {
42
                        //Reducimos el tama?o de la cache para una prueba con menos datos
43
                        BufferCacheManagerImpl.cacheSize = 2;
44
                        BufferCacheManagerImpl.pageSize = 0.2;
45
                        
46
                        for (int iTimes = 0; iTimes < REPEAT; iTimes++) {
47

    
48
                                //Read input data
49
                                input = new GdalRead(rasterIn);
50
                                Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
51

    
52
                                //Create Buffer
53
                                Buffer buf1 = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
54
                                                input.getWidth(), 
55
                                                input.getHeight(),
56
                                                input.getBandCount());
57

    
58
                                //Set data to buffer
59
                                setLines(dataIn, buf1);
60
                                
61
                                
62
                                for (int iBand = 0; iBand < buf1.getBandCount(); iBand++) {
63
                                        for (int i = 0; i < buf1.getHeight(); i++) {
64
                                                for (int j = 0; j < buf1.getWidth(); j++) {
65
                                                        byte b1 = buf1.getElemByte(i, j, iBand);
66
                                                        byte b2 = buf1.getElemByte(i, j, iBand);
67
                                                        aux = b1 * b2;
68
                                                }
69
                                        }
70
                                }
71
                                
72
                                buf1.free();
73
                        }
74
                } catch (GdalException e) {
75
                        e.printStackTrace();
76
                } catch (IOException e) {
77
                        e.printStackTrace();
78
                } catch (InterruptedException e) {
79
                        e.printStackTrace();
80
                } catch (OperationNotSupportedException e) {
81
                        e.printStackTrace();
82
                }
83
                long t2 = System.currentTimeMillis();
84
                System.out.println("Tiempo StripeCache TestCachePerformance: " + (t2 - t1) + " milisegundos");
85
        }
86
        
87
        private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
88
                if(dataIn instanceof byte[][][]) {
89
                    byte[][][] d = (byte[][][])dataIn;
90
                    for (int iBand = 0; iBand < d.length; iBand++) {
91
                                for (int row = 0; row < d[iBand].length; row++) {
92
                                        buf.setLineInBandByte(d[iBand][row], row, iBand);
93
                                }
94
                        }
95
            }
96
        }
97
        
98
}