/** * *********************************************************************** * * * Java Grande Forum Benchmark Suite - Version 2.0 * * * * produced by * * * * Java Grande Benchmarking Project * * * * at * * * * Edinburgh Parallel Computing Centre * * * * email: epcc-javagrande@epcc.ed.ac.uk * * * * * * This version copyright (c) The University of Edinburgh, 1999. * * All rights reserved. * * * * ************************************************************************ * * @author Shams Imam (shams@rice.edu) * */ package edu.rice.hj.example.applications.crypt; public class JGFTimer { public String name; public String opname; public double time; public double opcount; public long calls; public int size = -1; private long start_time; private boolean on; /** *

Constructor for JGFTimer.

* * @param name a {@link String} object. * @param opname a {@link String} object. */ public JGFTimer(String name, String opname) { this.name = name; this.opname = opname; reset(); } /** *

Constructor for JGFTimer.

* * @param name a {@link String} object. * @param opname a {@link String} object. * @param size a int. */ public JGFTimer(String name, String opname, int size) { this.name = name; this.opname = opname; this.size = size; reset(); } /** *

Constructor for JGFTimer.

* * @param name a {@link String} object. */ public JGFTimer(String name) { this(name, ""); } /** *

start.

*/ public void start() { if (on) { System.out.println("Warning timer " + name + " was already turned on"); } on = true; start_time = System.currentTimeMillis(); } /** *

stop.

*/ public void stop() { time += (double) (System.currentTimeMillis() - start_time) / 1000.; if (!on) { System.out.println("Warning timer " + name + " wasn't turned on"); } calls++; on = false; } /** *

addops.

* * @param count a double. */ public void addops(double count) { opcount += count; } /** *

reset.

*/ public void reset() { time = 0.0; calls = 0; opcount = 0; on = false; } /** *

perf.

* * @return a double. */ public double perf() { return opcount / time; } /** *

longprint.

*/ public void longprint() { System.out.println("Timer Calls Time(s) Performance(" + opname + "/s)"); System.out.println(name + " " + calls + " " + time + " " + this.perf()); } /** *

print.

*/ public void print() { if (opname.equals("")) { System.out.println(name + " " + time + " (s)"); } else { switch (size) { case 0: System.out.println(name + ":SizeA" + "\t" + time + " (s) \t " + (float) this.perf() + "\t" + " (" + opname + "/s)"); break; case 1: System.out.println(name + ":SizeB" + "\t" + time + " (s) \t " + (float) this.perf() + "\t" + " (" + opname + "/s)"); break; case 2: System.out.println(name + ":SizeC" + "\t" + time + " (s) \t " + (float) this.perf() + "\t" + " (" + opname + "/s)"); break; default: System.out.println(name + "\t" + time + " (s) \t " + (float) this.perf() + "\t" + " (" + opname + "/s)"); break; } } } /** *

printperf.

*/ public void printperf() { String name; name = this.name; // pad name to 40 characters while (name.length() < 40) { name = name + " "; } System.out.println(name + "\t" + (float) this.perf() + "\t" + " (" + opname + "/s)"); } }