Package org.nineml.coffeegrinder.util
Class StopWatch
- java.lang.Object
-
- org.nineml.coffeegrinder.util.StopWatch
-
public class StopWatch extends java.lang.ObjectA utility class for managing a "wall clock" timer.The timer starts when you create the object. Subsequent calls will return information based on the elapsed wall-clock time since the object was created. If
stopis called, it will fix the end time.
-
-
Constructor Summary
Constructors Constructor Description StopWatch()Create a stopwatch.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longduration()The number of milliseconds that the stopwatch has been running.java.lang.Stringelapsed()The elapsed time in a human-friendly format.java.lang.Stringelapsed(long duration)The elapsed time in a human-friendly format.java.lang.StringperSecond(long events)Compute events per second.voidstop()Stop the watch.
-
-
-
Method Detail
-
stop
public void stop()
Stop the watch.After calling this method, the time will remain fixed.
-
duration
public long duration()
The number of milliseconds that the stopwatch has been running.Or, if
stophas been called, how long it ran.- Returns:
- the number of milliseconds
-
perSecond
public java.lang.String perSecond(long events)
Compute events per second.Computes events per second for the given number of events. It returns a string of the form
%3.1f.- Parameters:
events- The number of events- Returns:
- A formatted string
-
elapsed
public java.lang.String elapsed()
The elapsed time in a human-friendly format.This method uses the timer's elapsed time.
- Returns:
- A formatted string
-
elapsed
public java.lang.String elapsed(long duration)
The elapsed time in a human-friendly format.Returns the number of days, minutes, hours, and seconds represented by the duration, a number of milliseconds. For example, 103,010,000ms is "1d4h36m50s".
- Parameters:
duration- the duration in milliseconds- Returns:
- A formatted string
-
-