jimm.util
Class StopWatch

java.lang.Object
  extended by jimm.util.StopWatch

public class StopWatch
extends java.lang.Object

Prints time durations; used for development purposes only.

No threads or system resources are harmed in the making of a stop watch. A stop watch simply remembers the start time (and elapsed time when paused) and prints the total "running" time when either mark() or stop() is called.

stop() doesn't really stop anything. You can call stop as many times as you like and it will print the time elapsed since start. It would be easy to change this behavior, but I haven't needed to.

Author:
Jim Menard, jimm@io.com

Field Summary
protected  long elapsedTime
           
protected  java.lang.String name
           
protected  java.io.PrintWriter out
           
protected  long t0
           
 
Constructor Summary
StopWatch()
           
StopWatch(java.io.PrintWriter out)
           
StopWatch(java.lang.String name)
           
StopWatch(java.lang.String name, java.io.PrintWriter out)
           
 
Method Summary
 void mark()
          Prints the current elapsed time without stopping.
 void mark(boolean printMark)
          Prints the current elapsed time without stopping, along with the stop watch name if printMark is true.
 void mark(java.lang.String msg)
          Prints the current elapsed time without stopping, along with the stop watch name and msg.
 void mark(java.lang.String msg, boolean printMark)
          Prints the current elapsed time without stopping, along with, along with the stop watch name if printMark is true and the msg if it's not null.
 void pause()
          Pauses the stop watch.
 void resume()
          Resumes the stop watch.
 void start()
          Remembers the current time and prints a message.
 void start(boolean printStarting)
          Remembers the current time and prints a message if requested.
 void stop()
          Stops the stop watch and prints the name of this stop watch and the current elapsed time.
 void stop(java.lang.String msg)
          Stops the stop watch and prints the name of this stop watch, msg if non-null, and the current elapsed time.
 void stop(java.lang.String msg, boolean printName)
          Prints the current elapsed time, along with the stop watch name if printMark is true and the msg if it's not null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

t0

protected long t0

elapsedTime

protected long elapsedTime

out

protected java.io.PrintWriter out
Constructor Detail

StopWatch

public StopWatch()

StopWatch

public StopWatch(java.lang.String name)

StopWatch

public StopWatch(java.io.PrintWriter out)

StopWatch

public StopWatch(java.lang.String name,
                 java.io.PrintWriter out)
Method Detail

start

public void start()
Remembers the current time and prints a message.


start

public void start(boolean printStarting)
Remembers the current time and prints a message if requested.

Parameters:
printStarting - if true and this stop watch has a name, print a message

pause

public void pause()
Pauses the stop watch.


resume

public void resume()
Resumes the stop watch.


mark

public void mark()
Prints the current elapsed time without stopping.


mark

public void mark(boolean printMark)
Prints the current elapsed time without stopping, along with the stop watch name if printMark is true.

Parameters:
printMark - if true, the stop watch name will be printed

mark

public void mark(java.lang.String msg)
Prints the current elapsed time without stopping, along with the stop watch name and msg.

Parameters:
msg - a message to print

mark

public void mark(java.lang.String msg,
                 boolean printMark)
Prints the current elapsed time without stopping, along with, along with the stop watch name if printMark is true and the msg if it's not null.

Parameters:
msg - a message to print
printMark - if true, the stop watch name will be printed

stop

public void stop()
Stops the stop watch and prints the name of this stop watch and the current elapsed time.


stop

public void stop(java.lang.String msg)
Stops the stop watch and prints the name of this stop watch, msg if non-null, and the current elapsed time.

Parameters:
msg - a message to print; may be null

stop

public void stop(java.lang.String msg,
                 boolean printName)
Prints the current elapsed time, along with the stop watch name if printMark is true and the msg if it's not null.

Parameters:
msg - a message to print; may be null
printName - if true, the stop watch name will be printed