Statistics
| Revision:

gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / test / vertical / TestCachePerformance.java @ 1965

History | View | Annotate | Download (3.22 KB)

1
package org.gvsig.raster.cache.buffer.impl.stripecache.vertical;
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

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

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

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

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

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