Package uk.ac.ebi.utils.time
Class XStopWatch
java.lang.Object
org.apache.commons.lang3.time.StopWatch
uk.ac.ebi.utils.time.XStopWatch
public class XStopWatch
extends org.apache.commons.lang3.time.StopWatch
A
StopWatch
with extended functionality.
- date
- 9 Apr 2014
- Author:
- Marco Brandizi
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic long
Wrapper ofprofileNano(Runnable)
returning time in ms.static long
profileNano
(Runnable task) Facility to profile (i.e., to time) a task.void
restart()
InvokesStopWatch.reset()
and thenStopWatch.start()
, ie, start a new timing session.void
IfStopWatch.isSuspended()
invokesStopWatch.resume()
as usually.long
long
This is similar toprofileNano(Runnable)
, but uses the current watch to time the parameter task.Methods inherited from class org.apache.commons.lang3.time.StopWatch
create, createStarted, formatSplitTime, formatTime, getDuration, getMessage, getNanoTime, getSplitDuration, getSplitNanoTime, getSplitTime, getStartInstant, getStartTime, getStopInstant, getStopTime, getTime, getTime, isStarted, isStopped, isSuspended, reset, resume, split, start, stop, suspend, toSplitString, toString, unsplit
-
Constructor Details
-
XStopWatch
public XStopWatch()
-
-
Method Details
-
resumeOrStart
public void resumeOrStart()IfStopWatch.isSuspended()
invokesStopWatch.resume()
as usually. IfStopWatch.isStopped()
callsStopWatch.start()
, if neither is true, it means it's already started and hence does nothing. -
restart
public void restart()InvokesStopWatch.reset()
and thenStopWatch.start()
, ie, start a new timing session. -
profileNano
Facility to profile (i.e., to time) a task.- Returns:
- the time elapsed between before and after
task.run()
. This usestrackNano(Runnable)
.
-
profile
Wrapper ofprofileNano(Runnable)
returning time in ms. -
trackNano
This is similar toprofileNano(Runnable)
, but uses the current watch to time the parameter task. At the end of this method, the current watch will be suspended, every new call to this method will resume the watch and hence the times measured for multiple tasks are added up.- Returns:
- the time elapsed since the call to this method and the end of the task parameter. Note that timing a task in a multi-thread context might give wrong results, since here we simply measure the time elapsed from start to end, we don't consider the parallelism in between.
-
track
- See Also:
-
wrapper of #trackNano(Runnable), which just converts the result to ms.
-