Class NanoWatch
java.lang.Object
fc.util.Watch
fc.util.NanoWatch
Allows measuring the start and stop time and (hence the elapsed time) of
some event. ("event" meaning something of interest, for example, a method
call). Can be started/stopped repeatedly. (cumulative time across all such
start/stops are available via the
cumulativeTime() method).
All times are in nano-seconds.
Thread Safety: This class is not threadsafe and it's method do not acquire any locks to reduce any time skew due to lock acquisition. Multiple threads should use separate NanoWatch objects or alternatively, higher level synchronization.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the total time recorded by this Watch (across several starts/stops)longgetTime()Returns the time elapsed since the Watch was started.doubleReturns the elapsed time in milliseconds.booleanIs the Watch currently running ?static voidvoidreset()Reset all values to zero.start()Start measuring time.voidstop()Stop measuring the timelongtime()Returns the time elapsed since the Watch was started.toString()Describes the current state of this watch.Methods inherited from class Watch
elapsed, getTimeInSeconds, restart, seconds, timeInSeconds, timeMillis, timeSeconds
-
Constructor Details
-
NanoWatch
-
NanoWatch
public NanoWatch()
-
-
Method Details
-
start
-
stop
-
time
Returns the time elapsed since the Watch was started. If the watch was started and stopped, returns the time between the start/stop interval.- Overrides:
timein classWatch- Throws:
RuntimeException- if the watch was never started before calling this method.
-
getTime
-
getTimeInMillis
Returns the elapsed time in milliseconds. Useful when nanosecond values are too hard to read.- Overrides:
getTimeInMillisin classWatch
-
cumulativeTime
Returns the total time recorded by this Watch (across several starts/stops)- Overrides:
cumulativeTimein classWatch
-
reset
-
isRunning
-
toString
-
main
-