start of new file
[IRC.git] / Robust / src / Benchmarks / Prefetch / Crypt / dsm / jgfutil / 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 *                       Ported for DSTM Benchmark                         *
22 **************************************************************************/
23
24
25 //package jgfutil;
26
27 public class JGFTimer {
28
29   public String name; 
30   public String opname; 
31   public double time; 
32   public double opcount; 
33   public long calls; 
34   public int size;
35   
36   private long start_time;
37   private boolean on; 
38
39   public JGFTimer(String name, String opname){
40     this.name = name;
41     this.opname = opname;
42     this.size = -1;
43     reset(); 
44   }
45
46   public JGFTimer(String name, String opname, int size){
47     this.name = name;
48     this.opname = opname;
49     this.size = size;
50     reset();
51   }
52
53   public JGFTimer(String name){
54     this.name = name;
55     this.opname = "";
56     reset(); 
57   }
58
59
60
61   public void start(){
62     if (on) System.printString("Warning timer " + name + " was already turned on");
63     on = true; 
64     start_time = System.currentTimeMillis();
65   }
66
67
68   public void stop(){
69     time += (double) (System.currentTimeMillis()-start_time) / 1000.;
70     if (!on) System.printString("Warning timer " + name + " wasn't turned on");
71     calls++;
72     on = false;  
73   }
74
75   public void addops(double count){
76     opcount += count;
77   } 
78
79   public void addtime(double added_time){
80     time += added_time;
81   }
82
83   public void reset(){
84     time = 0.0; 
85     calls = 0; 
86     opcount = 0; 
87     on = false;
88   }
89
90   public double perf(){
91     return opcount / time; 
92   }
93
94   public void longprint(){
95       System.printString("Timer            Calls         Time(s)       Performance("+opname+"/s)");   
96      //System.printString(name + "           " + calls +    "           "  +  time + "        " + this.perf());
97   }
98
99   public void print(){
100     if (opname.equals(""))
101     {
102       System.printString(name + "   " + (long)time + " (s)");
103     }
104     else
105     {
106       if(size == 0) {
107         System.printString(name + ":SizeA" + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)");
108       } else if (size == 1) {
109         System.printString(name + ":SizeB" + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)");
110       } else if (size == 2) {
111         System.printString(name + ":SizeC" + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)");
112       } else{
113         System.printString(name + "\t" + (long)time + " (s) \t " + (long)this.perf() + "\t" + " ("+opname+"/s)");
114       }
115     }
116   }
117
118   public void printperf(){
119
120      String name;
121      name = this.name; 
122
123      // pad name to 40 characters
124      while ( name.length() < 40 ) name = name + " "; 
125      
126      System.printString(name + "\t" + (long)this.perf() + "\t"
127                         + " ("+opname+"/s)");  
128   }
129
130 }