Top Description Fields Constructors Methods
org.hsqldb.lib

public Class StopWatch

extends Object
Class Inheritance

Provides the programatic analog of a physical stop watch.

The watch can be started, stopped and zeroed and can be queried for elapsed running time. The watch accumulates elapsed time over starts and stops such that only the time actually spent running is recorded. If the watch is zeroed, then the accumulated time is discarded and the watch starts again with zero accumulated time.

Nanosecond support added by fredt@users

Author
Campbell Burnet (campbell-burnet@users dot sourceforge.net)
Since
1.7.2
Version
2.6.0

Field Summary

Modifier and TypeField and Description
private long
pack-priv boolean
running

Flags if this object is started or stopped.

private long
startTime

The last time this object made the transition from stopped to running state, as reported by System.nanoTime().

private long
total

The accumulated running time of this object since it was last zeroed.

Constructor Summary

AccessConstructor and Description
public
StopWatch()

Creates, zeros, and starts a new StopWatch

public
StopWatch(boolean
boolean
start
)

Creates, zeros, and starts a new StopWatch

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

the accumulated nanoseconds this object has spent running since it was last started.
currentElapsedNanos
()

Retrieves the accumulated nanoseconds this object has spent running since it was last started.

public String

Returns:

prefix + " in " + elapsedTime() + " ns."
currentElapsedNanosToMessage
(String
The string to use as a prefix
prefix
)

Retrieves prefix + " in " + elapsedTime() + " ns."

public long

Returns:

the accumulated milliseconds this object has spent running since it was last started.
currentElapsedTime
()

Retrieves the accumulated milliseconds this object has spent running since it was last started.

public String

Returns:

prefix + " in " + elapsedTime() + " ms."
currentElapsedTimeToMessage
(String
The string to use as a prefix
prefix
)

Retrieves prefix + " in " + elapsedTime() + " ms."

public long

Returns:

the accumulated nanoseconds this object has spent running since it was last zeroed.
elapsedNanos
()

Retrieves the accumulated nanoseconds this object has spent running since it was last zeroed.

public String

Returns:

prefix + " in " + elapsedNanos() + " ns."
elapsedNanosToMessage
(String
The string to use as a prefix
prefix
)

Retrieves prefix + " in " + elapsedNanos() + " ns."

public long

Returns:

the accumulated milliseconds this object has spent running since it was last zeroed.
elapsedTime
()

Retrieves the accumulated milliseconds this object has spent running since it was last zeroed.

public String

Returns:

prefix + " in " + elapsedTime() + " ms."
elapsedTimeToMessage
(String
The string to use as a prefix
prefix
)

Retrieves prefix + " in " + elapsedTime() + " ms."

public void
mark()

public void
start()

Ensures that this object is in the running state.

public void
stop()

Ensures that this object is in the stopped state.

public String

Returns:

the state of this object, as a String
toString
()

Overrides java.lang.Object.toString.

Retrieves the internal state of this object, as a String.

public void
zero()

Zeros accumulated running time and restarts this object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

lastStartback to summary
private long lastStart
runningback to summary
pack-priv boolean running

Flags if this object is started or stopped.

startTimeback to summary
private long startTime

The last time this object made the transition from stopped to running state, as reported by System.nanoTime().

totalback to summary
private long total

The accumulated running time of this object since it was last zeroed.

Constructor Detail

StopWatchback to summary
public StopWatch()

Creates, zeros, and starts a new StopWatch

StopWatchback to summary
public StopWatch(boolean start)

Creates, zeros, and starts a new StopWatch

Parameters
start:boolean

boolean

Method Detail

currentElapsedNanosback to summary
public long currentElapsedNanos()

Retrieves the accumulated nanoseconds this object has spent running since it was last started.

Returns:long

the accumulated nanoseconds this object has spent running since it was last started.

currentElapsedNanosToMessageback to summary
public String currentElapsedNanosToMessage(String prefix)

Retrieves prefix + " in " + elapsedTime() + " ns."

Parameters
prefix:String

The string to use as a prefix

Returns:String

prefix + " in " + elapsedTime() + " ns."

currentElapsedTimeback to summary
public long currentElapsedTime()

Retrieves the accumulated milliseconds this object has spent running since it was last started.

Returns:long

the accumulated milliseconds this object has spent running since it was last started.

currentElapsedTimeToMessageback to summary
public String currentElapsedTimeToMessage(String prefix)

Retrieves prefix + " in " + elapsedTime() + " ms."

Parameters
prefix:String

The string to use as a prefix

Returns:String

prefix + " in " + elapsedTime() + " ms."

elapsedNanosback to summary
public long elapsedNanos()

Retrieves the accumulated nanoseconds this object has spent running since it was last zeroed.

Returns:long

the accumulated nanoseconds this object has spent running since it was last zeroed.

elapsedNanosToMessageback to summary
public String elapsedNanosToMessage(String prefix)

Retrieves prefix + " in " + elapsedNanos() + " ns."

Parameters
prefix:String

The string to use as a prefix

Returns:String

prefix + " in " + elapsedNanos() + " ns."

elapsedTimeback to summary
public long elapsedTime()

Retrieves the accumulated milliseconds this object has spent running since it was last zeroed.

Returns:long

the accumulated milliseconds this object has spent running since it was last zeroed.

elapsedTimeToMessageback to summary
public String elapsedTimeToMessage(String prefix)

Retrieves prefix + " in " + elapsedTime() + " ms."

Parameters
prefix:String

The string to use as a prefix

Returns:String

prefix + " in " + elapsedTime() + " ms."

markback to summary
public void mark()
startback to summary
public void start()

Ensures that this object is in the running state. If this object is not running, then the call has the effect of setting the startTime attribute to the current value of System.nanoTime() and setting the running attribute to true.

stopback to summary
public void stop()

Ensures that this object is in the stopped state. If this object is in the running state, then this has the effect of adding to the total attribute the elapsed time since the last transition from stopped to running state and sets the running attribute to false. If this object is not in the running state, this call has no effect.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Retrieves the internal state of this object, as a String. The retrieved value is:

   super.toString() +
   "[running=" +
   running +
   ", startTime=" +
   startTime +
   ", total=" +
   total + "]";
Returns:String

the state of this object, as a String

zeroback to summary
public void zero()

Zeros accumulated running time and restarts this object.