8644d2c894a9a7e8e8578b574905a10292b14139
[IRC.git] / Robust / src / Benchmarks / Prefetch / Moldyn / java / JGFTimer.java
1 /**************************************************************************
2  *                                                                         *
3  *         Java Grande Forum Benchmark Suite - Thread Version 1.0          *
4  *                                                                         *
5  *                            produced by                                  *
6  *                                                                         *
7  *                  Java Grande Benchmarking Project                       *
8  *                                                                         *
9  *                                at                                       *
10  *                                                                         *
11  *                Edinburgh Parallel Computing Centre                      *
12  *                                                                         * 
13  *                email: epcc-javagrande@epcc.ed.ac.uk                     *
14  *                                                                         *
15  *                                                                         *
16  *      This version copyright (c) The University of Edinburgh, 1999.      *
17  *                         All rights reserved.                            *
18  *                                                                         *
19  **************************************************************************/
20
21 public class JGFTimer {
22
23   public String name; 
24   public String opname; 
25   public double time; 
26   public double opcount; 
27   public long calls; 
28   public int size;
29
30   private long start_time;
31   private boolean on; 
32
33   public JGFTimer(String name, String opname){
34     this.size = -1;
35     this.name = name;
36     this.opname = opname;
37     reset(); 
38   }
39
40   public JGFTimer(String name, String opname, int size){
41     this.name = name;
42     this.opname = opname;
43     this.size = size;
44     reset();
45   }
46
47   public JGFTimer(String name){
48     this(name,""); 
49   }
50
51
52
53   public void start(){
54     if (on) System.out.println("Warning timer " + name + " was already turned on");
55     on = true; 
56     start_time = System.currentTimeMillis();
57   }
58
59
60   public void stop(){
61     time += (double) (System.currentTimeMillis()-start_time) / 1000.;
62     if (!on) System.out.println("Warning timer " + name + " wasn't turned on");
63     calls++;
64     on = false;  
65   }
66
67   public void addops(double count){
68     opcount += count;
69   } 
70
71   public void addtime(double added_time){
72     time += added_time;
73   }
74
75   public void reset(){
76     time = 0.0; 
77     calls = 0; 
78     opcount = 0; 
79     on = false;
80   }
81
82   public double perf(){
83     return opcount / time; 
84   }
85
86   public void longprint(){
87     System.out.println("Timer            Calls         Time(s)       Performance("+opname+"/s)");   
88     System.out.println(name + "           " + calls +    "           "  +  time + "        " + this.perf());
89   }
90
91   public void print(){
92     if (opname.equals("")) {
93       System.out.println(name + "   " + time + " (s)");
94     }
95     else {
96
97       switch(size) {
98         case 0:
99           System.out.println(name + ":SizeA" + "\t" + time + " (s) \t " + (float)this.perf() + "\t"
100               + " ("+opname+"/s)");
101           break;
102         case 1:
103           System.out.println(name + ":SizeB" + "\t" + time + " (s) \t " + (float)this.perf() + "\t"
104               + " ("+opname+"/s)");
105           break;
106         case 2:
107           System.out.println(name + ":SizeC" + "\t" + time + " (s) \t " + (float)this.perf() + "\t"
108               + " ("+opname+"/s)");
109           break;
110         default:
111           System.out.println(name + "\t" + time + " (s) \t " + (float)this.perf() + "\t"
112               + " ("+opname+"/s)");
113           break;
114       }
115
116     }
117   }
118
119
120   public void printperf(){
121
122     String name;
123     name = this.name; 
124
125     // pad name to 40 characters
126     while ( name.length() < 40 ) name = name + " "; 
127
128     System.out.println(name + "\t" + (float)this.perf() + "\t"
129         + " ("+opname+"/s)");  
130   }
131
132 }