public final class Timer extends Object implements Comparable<Timer>, Reusable, Serializable, Cloneable
System.nanoTime()
). This timer is not synchronized.
It's up to the user to ensure thread safety.Constructor and Description |
---|
Timer()
Create a new Timer object.
|
Timer(String label)
Create a new time with the given label.
|
Modifier and Type | Method and Description |
---|---|
Timer |
clone() |
int |
compareTo(Timer timer) |
boolean |
equals(Object object) |
Measurable<Duration> |
getInterimTime()
|
String |
getLabel()
Return the timer label.
|
Measurable<Duration> |
getTime()
Return the overall time of this timer.
|
int |
hashCode() |
void |
reset()
Reset the timer.
|
void |
setAccumulator(Accumulator<? super Long> accumulator)
Set the accumulator for the interim results.
|
void |
setLabel(String label)
Set the timer label.
|
void |
start()
Start the timer.
|
void |
stop()
Stop the timer.
|
String |
toString() |
public Timer(String label)
toString()
method.label
- the timer label.NullPointerException
- if the label
is null
.public Timer()
public void setAccumulator(Accumulator<? super Long> accumulator)
final Mean<Long> variance = new Mean<>();
final Timer timer = new Timer();
timer.setAccumulator(variance);
for (int i = 0; i < 100; ++I) {
timer.start();
... // Do some measurable task.
timer.stop();
}
// Print the average time used for the 'measurable' task.
System.out.println(mean.getMean());
accumulator
- the accumulator used for the interim results.NullPointerException
- if the accumulator
is null
.public void start()
public void stop()
public Measurable<Duration> getTime()
final Timer timer = new Timer();
for (int i = 0; i < 10; ++i) {
timer.start();
Thread.sleep(1000);
timer.stop();
}
public Measurable<Duration> getInterimTime()
public void setLabel(String label)
label
- the new timer labelpublic int compareTo(Timer timer)
compareTo
in interface Comparable<Timer>
© 2007-2014 Franz Wilhelmstötter (2014-03-07 19:35)