/Users/lyon/j4p/src/ip/gui/BenchMark.java

1    package ip.gui; 
2     
3    import ip.gui.dialog.MessLog; 
4    import ip.gui.frames.TopFrame; 
5     
6    import java.awt.*; 
7     
8    public class BenchMark { 
9        TopFrame tf = null; 
10    
11       public void run(TopFrame _tf) { 
12           //System.out.println("Bench marks"); 
13           tf = _tf; 
14           doFplaneMark(); 
15       } 
16    
17       public void doFplaneMark() { 
18           Timer t = new Timer(); 
19           int N = 5; 
20           //System.out.println( 
21           //  "Running fplane mark,malloc 100MB.."+ 
22           //  "convolve "+N+" times with\n"+ 
23           //  "new Fplane(512,512)\n"+ 
24           //  "tf.lp2()\n"+ 
25           //  "tf.hp3()\n"+ 
26           //  "tf.zedSquare()\n"+ 
27           //  "tf.laplacian5()\n"+ 
28           //  "tf.fftR2()\n"+ 
29           //  "tf.ifftR2()\n"+ 
30           //  "tf.revert()\n"); 
31           t.start(); 
32           for (int i = 0; i < N; i++) { 
33               new Fplane(512, 512); 
34               tf.lp2(); 
35               tf.hp3(); 
36               tf.zedSquare(); 
37               tf.laplacian5(); 
38               tf.fftR2(); 
39               tf.ifftR2(); 
40               tf.sobel3(); 
41               tf.thresh(); 
42               tf.skeleton(); 
43               tf.revert(); 
44           } 
45           t.stop(); 
46           new MessLog(new Frame(), 
47                   "BenchMark", 
48                   t.elapsed() + " seconds"); 
49           //System.out.println("Total benchmarkTime"); 
50           //t.report(); 
51       } 
52    
53       class Fplane { 
54           public float r[][]; 
55           public float g[][]; 
56           public float b[][]; 
57    
58           Fplane(int w, int h) { 
59               r = new float[w][h]; 
60               g = new float[w][h]; 
61               b = new float[w][h]; 
62           } 
63       } 
64    
65       class Timer { 
66           private long base_time; 
67           private long elapsed_time; 
68    
69           private long UNIT = 1000; 
70    
71    
72           public void start() { 
73               base_time = System.currentTimeMillis(); 
74           } 
75    
76    
77           public void stop() { 
78               elapsed_time = 
79                       (System.currentTimeMillis() - base_time); 
80           } 
81    
82           public float elapsed() { 
83               return ((float) elapsed_time) / UNIT; 
84           } 
85    
86           public void report() { 
87               float elapsed_seconds = elapsed(); 
88               System.out.println( 
89                       "Time " + elapsed_seconds + " sec"); 
90           } 
91    
92       } 
93    
94   } 
95    
96    
97    
98    
99