|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.util.timer.PerformanceTimer
public class PerformanceTimer
A simple timer for measuring code performance. You can register
one or more timers when constructing an object of this class. Typically,
there should be one timer for each part of the code (method call) that
you want to measure.
Use start(int)
, stop(int)
and stopStart(int, int)
to start and stop the timers in your code. Example:
PerformanceTimer timer = new PerformanceTimer("method1()", "method2()"); timer.start(0); method1(); timer.stopStart(0, 1); method2(); timer.stop(1); System.out.println(timer.toString());This classes use
System.nanoTime()
to get the time. All times
are returned as nano-second differences between the start and stop time
of the timer. Starting and stopping a timer multiple times adds more
time to the timer. Use reset(int)
to zero a timer.
Field Summary | |
---|---|
private boolean[] |
isRunning
|
private String[] |
names
|
private long[] |
timers
|
Constructor Summary | |
---|---|
PerformanceTimer(String... names)
Create a new timer object for measuring one or more times. |
Method Summary | |
---|---|
long |
getTime(int index)
Get the current time of a timer. |
boolean |
isRunning(int index)
Check if a timer is running or not. |
void |
reset(int index)
Reset a timer. |
void |
resetAll()
Reset all timers. |
void |
start(int index)
Start the timer with the given index. |
long |
stop(int index)
Stop a running timer. |
void |
stopAll()
Stop all running timers |
long |
stopStart(int stopIndex,
int startIndex)
Start one timer and stop another. |
String |
toString()
Print out time information about each timer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private final String[] names
private final long[] timers
private final boolean[] isRunning
Constructor Detail |
---|
public PerformanceTimer(String... names)
names
- The name of the timersMethod Detail |
---|
public void start(int index)
index
- The index of the timerpublic long stop(int index)
index
- The index of the timer
public long stopStart(int stopIndex, int startIndex)
stopIndex
- The timer to stopstartIndex
- The timer to start
public void stopAll()
public boolean isRunning(int index)
index
- The index of the timer
public long getTime(int index)
index
- The index of the timer
public void reset(int index)
index
- The timer to resetpublic void resetAll()
public String toString()
toString
in class Object
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |