Package org.sosy_lab.common.time
Class Timer
java.lang.Object
org.sosy_lab.common.time.Timer
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 to
Stopwatch but has more features.
This class is not thread-safe and may be used only from within a single thread.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturn the average of all intervals.Return the length of the last measured interval.Return the maximal time of all intervals.Return the minimal time of all intervals.intReturn the number of intervals.Return the sum of all intervals.booleanCheck if the timer is running.Syntax sugar method: pretty-format the timer output into a string in seconds.voidstart()Start the timer.voidstop()Stop the timer.voidtoString()Return a String with a default representation of the the sum of the times of all intervals.
-
Constructor Details
-
Timer
public Timer()Create a fresh timer in the not-running state.
-
-
Method Details
-
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
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
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
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
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
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
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
Syntax sugar method: pretty-format the timer output into a string in seconds.
-