edu.rice.cs.plt.debug
Class Stopwatch

java.lang.Object
  extended by edu.rice.cs.plt.debug.Stopwatch

public class Stopwatch
extends Object

A simple timer based on System.currentTimeMillis(). To support better performance, this class is not thread-safe.


Constructor Summary
Stopwatch()
          Create a new stopwatch with no split times and in a stopped state.
Stopwatch(boolean startImmediately)
          Create a new stopwatch with no split times; if startImmediately is true, start the timer before returning.
 
Method Summary
 long split()
          Record and return the number of milliseconds since start() was invoked.
 Iterable<Long> splits()
          Get a dynamically-updating view of all splits recorded by the stopwatch.
 void start()
          Start the timer.
 long stop()
          Stop the timer; record and return the number of milliseconds since start() was invoked.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Stopwatch

public Stopwatch()
Create a new stopwatch with no split times and in a stopped state.


Stopwatch

public Stopwatch(boolean startImmediately)
Create a new stopwatch with no split times; if startImmediately is true, start the timer before returning.

Method Detail

start

public void start()
Start the timer.

Throws:
IllegalStateException - If the stopwatch is currently running.

split

public long split()
Record and return the number of milliseconds since start() was invoked.

Throws:
IllegalStateException - If the stopwatch is not currently running.

stop

public long stop()
Stop the timer; record and return the number of milliseconds since start() was invoked.

Throws:
IllegalStateException - If the stopwatch is not currently running.

splits

public Iterable<Long> splits()
Get a dynamically-updating view of all splits recorded by the stopwatch. (Create a IterUtil.snapshot(java.lang.Iterable) if the stopwatch is to be used while iterating over this list.)