SimpleStopWatch

Minimalistic stopwatch to measure the elapsed time between operations.

This stopwatch does not support multi-threading. When implementing this stopwatch, make sure to take care of this properly, otherwise inconsistency and unexpected errors will be a problem for you. This stopwatch uses Clock.System.now to retrieve both the start-time and stop-time. A regular run expects you to call start, followed by stop, and then either of getTime or toString to retrieve the elapsed time as a formatted string.

Author

Griefed

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var startTime: Instant
Link copied to clipboard
Link copied to clipboard
var stopTime: Instant

Functions

Link copied to clipboard

Get the elapsed time in nanoseconds. Depending on the state of the stopwatch, two values or an IllegalStateException may be thrown.

Link copied to clipboard
fun getTime(unit: DurationUnit = DurationUnit.SECONDS, decimals: Int = 2): String

Duration value expressed in the given unit and formatted with the specified decimals-amount of digits after the decimal point.

Link copied to clipboard

Starts the stopwatch.

Link copied to clipboard

Stops the stopwatch.

Link copied to clipboard
open override fun toString(): String

Get the elapsed time of this stopwatch, formatted using %2dh:%02dm:%02ds:%04dms.