nl.uu.cs.treewidth.timing
Class Stopwatch

java.lang.Object
  extended by nl.uu.cs.treewidth.timing.Stopwatch

public class Stopwatch
extends java.lang.Object

A stopwatch can be used to measure intervals.

Example usage: Simple timing.

 Stopwatch t = new Stopwatch();
 
 t.start();
  ... do something ...
 t.stop();
 
 long millisecondsPassed = t.getTime(); 
 

Example usage: repeat something until a second has passed. (Note that this only checks the time once every iteration, so it `do something' is expensive you can significantly overshoot one second.)

 Stopwatch t = new Stopwatch();
 
 t.start();
 while( t.getTime() < 1000 ) {
     ... do something ...
 }
 t.stop();
 

Example usage: Using a custom TimeSource.

 Stopwatch t = new Stopwatch( new JavaNanoTime() );
 

Author:
tw team

Constructor Summary
Stopwatch()
          Constructs a fresh Stopwatch.
Stopwatch(TimeSource timeSource)
          Constructs a fresh Stopwatch which will use the provided TimeSource.
 
Method Summary
 long getTime()
           
 void reset()
           
 void start()
          Start counting time.
 void stop()
          Stop counting time.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Stopwatch

public Stopwatch()
Constructs a fresh Stopwatch.
TODO Should I mention here which TimeSource it defaults to?


Stopwatch

public Stopwatch(TimeSource timeSource)
Constructs a fresh Stopwatch which will use the provided TimeSource.

Parameters:
timeSource -
Method Detail

start

public void start()
Start counting time.
Does nothing if the stopwatch is already started. This means that you cannot nest start()/stop() calls: a stop() always stops the counting of time, no matter how many start()s have gone in between.


stop

public void stop()
Stop counting time.
Does nothing if the stopwatch is not running. Always stops counting time: this means that you cannot nest start()/stop() calls.


reset

public void reset()

getTime

public long getTime()
Returns:
The current time on the stopwatch. What this number means depends on the TimeSource.