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