01: /*
02: * Primitive Collections for Java.
03: * Copyright (C) 2003 Søren Bak
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19: package bak.pcj.benchmark;
20:
21: /**
22: * This class represents benchmark tests. All benchmarks should
23: * inherit this class. When writing a benchmark, create public
24: * methods starting with "benchmark" and taking one argument of
25: * class {@link DataSet DataSet}. After invoking each of these
26: * methods, the benchmark runner will read the benchmark's timer
27: * to produce a result. Within such a benchmark method, the timer
28: * should be started when initialization is done and stopped when
29: * the operations are done. The pattern is this:
30: * <pre>
31: * public String benchmarkXXXXX(DataSet dataSet) {
32: * <initialize>
33: * startTimer();
34: * <operations to benchmark>
35: * stopTimer();
36: * <clean up>
37: * return "description of task";
38: * }
39: * </pre>
40: *
41: * @author Søren Bak
42: * @version 1.0 2003/4/1
43: * @since 1.0
44: */
45: public abstract class Benchmark {
46:
47: private long startTime;
48: private long endTime;
49:
50: /**
51: * Starts the timer to measure operations.
52: */
53: protected void startTimer() {
54: startTime = System.currentTimeMillis();
55: }
56:
57: /**
58: * Starts the timer to measure operations.
59: */
60: protected void stopTimer() {
61: endTime = System.currentTimeMillis();
62: }
63:
64: /**
65: * Returns the last timing result. If no timing result is
66: * available, the return value is undefined.
67: *
68: * @return the last timing result.
69: */
70: public long readTimer() {
71: return endTime - startTime;
72: }
73:
74: /**
75: * Returns the name of the class that is benchmarked.
76: *
77: * @return the name of the class that is benchmarked.
78: */
79: public abstract String getClassId();
80:
81: }
|