KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bak > pcj > benchmark > Benchmark


1 /*
2  * Primitive Collections for Java.
3  * Copyright (C) 2003 Søren Bak
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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  * &lt;initialize&gt;
33  * startTimer();
34  * &lt;operations to benchmark&gt;
35  * stopTimer();
36  * &lt;clean up&gt;
37  * return "description of task";
38  * }
39  * </pre>
40  *
41  * @author S&oslash;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      * Starts the timer to measure operations.
58      */

59     protected void stopTimer()
60     { endTime = System.currentTimeMillis(); }
61
62     /**
63      * Returns the last timing result. If no timing result is
64      * available, the return value is undefined.
65      *
66      * @return the last timing result.
67      */

68     public long readTimer()
69     { return endTime - startTime; }
70
71     /**
72      * Returns the name of the class that is benchmarked.
73      *
74      * @return the name of the class that is benchmarked.
75      */

76     public abstract String JavaDoc getClassId();
77
78 }
Popular Tags