start of new file
[IRC.git] / Robust / src / Benchmarks / Prefetch / SOR / dsm / 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 = name;
49     this.opname = "";
50     reset();
51   }
52
53
54
55   public void start(){
56     if (on) System.printString("Warning timer " + " was already turned on\n");
57     on = true; 
58     start_time = System.currentTimeMillis();
59   }
60
61
62   public void stop(){
63     time += (double) (System.currentTimeMillis()-start_time) / 1000.;
64     if (!on) System.printString("Warning timer " + " wasn't turned on\n");
65     calls++;
66     on = false;  
67   }
68
69   public void addops(double count){
70     opcount += count;
71   } 
72
73   public void addtime(double added_time){
74     time += added_time;
75   }
76
77   public void reset(){
78     time = 0.0; 
79     calls = 0; 
80     opcount = 0; 
81     on = false;
82   }
83
84   public double perf(){
85     return opcount / time; 
86   }
87
88   public void longprint(){
89     System.printString("Timer            Calls         Time(s)       Performance("+opname+"/s)\n");   
90     System.printString(name + "           " + calls +    "           "  +  (long)time + "        " + (long)this.perf() + "\n");
91   }
92
93   public void print(){
94     if (opname.equals("")) {
95       System.printString(name + "   " + (long)time + " (s)\n");
96     }
97     else {
98       if(size == 0) {
99         System.printString(name + ":SizeA" + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)\n");
100       } else if (size == 1) {
101         System.printString(name + ":SizeB" + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)\n");
102       } else if (size == 2) {
103         System.printString(name + ":SizeC" + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)\n");
104       } else{
105         System.printString(name + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)\n");
106       }
107     }
108   }
109
110
111   public void printperf(){
112
113     String name;
114     name = this.name; 
115
116     // pad name to 40 characters
117     while ( name.length() < 40 ) name = name + " "; 
118
119     System.printString(name + "\t" + (long)this.perf() + "\t"
120         + " ("+opname+"/s)\n");  
121   }
122
123 }