Package org.sosy_lab.common.time
Class Timer
- java.lang.Object
-
- org.sosy_lab.common.time.Timer
-
public final class Timer extends Object
This class represents a timer like a stop watch. It can be started and stopped several times. It measures the sum, the average, the minimum, the maximum and the number of those intervals. This class is similar toStopwatch
but has more features.This class is not thread-safe and may be used only from within a single thread.
-
-
Constructor Summary
Constructors Constructor Description Timer()
Create a fresh timer in the not-running state.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TimeSpan
getAvgTime()
Return the average of all intervals.TimeSpan
getLengthOfLastInterval()
Return the length of the last measured interval.TimeSpan
getMaxTime()
Return the maximal time of all intervals.TimeSpan
getMinTime()
Return the minimal time of all intervals.int
getNumberOfIntervals()
Return the number of intervals.TimeSpan
getSumTime()
Return the sum of all intervals.boolean
isRunning()
Check if the timer is running.String
prettyFormat()
Syntax sugar method: pretty-format the timer output into a string in seconds.void
start()
Start the timer.void
stop()
Stop the timer.void
stopIfRunning()
String
toString()
Return a String with a default representation of the the sum of the times of all intervals.
-
-
-
Method Detail
-
start
public void start()
Start the timer. May be called only if the timer is currently not running.
-
stop
public void stop()
Stop the timer. May be called only if the timer is currently running.
-
stopIfRunning
public void stopIfRunning()
-
isRunning
public boolean isRunning()
Check if the timer is running. Contrary to all other methods of this class, this method is thread-safe. This means it can be safely run from another thread.
-
getSumTime
public TimeSpan getSumTime()
Return the sum of all intervals. If timer is running, the current interval is also counted (up to the current time). If the timer was never started, this method returns 0.
-
getMaxTime
public TimeSpan getMaxTime()
Return the maximal time of all intervals. If timer is running, the current interval is also counted (up to the current time). If the timer was never started, this method returns 0.
-
getMinTime
public TimeSpan getMinTime()
Return the minimal time of all intervals. If the timer is running, the current interval is not considered. If the timer was never started, this method returns 0.
-
getNumberOfIntervals
public int getNumberOfIntervals()
Return the number of intervals. If timer is running, the current interval is also counted. If the timer was never started, this method returns 0.
-
getLengthOfLastInterval
public TimeSpan getLengthOfLastInterval()
Return the length of the last measured interval. If the timer is running, this is the time from the start of the current interval up to now. If the timer was never started, this method returns 0.
-
getAvgTime
public TimeSpan getAvgTime()
Return the average of all intervals. If timer is running, the current interval is also counted (up to the current time). If the timer was never started, this method returns 0.
-
toString
public String toString()
Return a String with a default representation of the the sum of the times of all intervals. For printing other times, or with a specific unit, use the appropriate getter and callTimeSpan.formatAs(java.util.concurrent.TimeUnit)
. The format and the content of the String returned by this method is not guaranteed to be the same in future versions of this code.
-
prettyFormat
public String prettyFormat()
Syntax sugar method: pretty-format the timer output into a string in seconds.
-
-