com.marringtons.time
Class Timer

java.lang.Object
  extended bycom.marringtons.time.Timer

public class Timer
extends Object

Use to measure and print timing information in the code.

 Timer timer = new Timer();
 .....
 String message = timer.toString();	//  implicit stop
 .....
 timer.println();	// implicit stop
 .....
 Log.message( timer.stop());	// record it to the log (could have used toString()
 .....
 System.out.println( timer); // stop is implicit
 
All the examples above will display same times from the first stop. To get the time between 2 points after the creation, use timer.reset() at the start point.

Author:
Paul Marrington

Constructor Summary
Timer()
          The default constructor will instantiate and start a timer object.
Timer(String message)
          This constructor attaches a text message to a timer for later display.
 
Method Summary
 void print()
          Stop timer and print result to stdout
 void print(String msg)
          Stop timer and print result to stdout.
 void println()
          Stop timer and print result to stdout including a carriage-return
 void println(String msg)
          Stop timer and print result to stdout including a carriage-return
 void reset()
          Reset the start time (same as creating a new object)
 float secondsElapsed()
          Stops timer if running and returns seconds elapsed since creation or last reset
 String stop()
          Sets the end time
 String stop(String msg)
          Sets the end time and returns the elapsed time and message.
 String toString()
          Returns a string with attached message and elapsed seconds in brackets.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Timer

public Timer()
The default constructor will instantiate and start a timer object.


Timer

public Timer(String message)
This constructor attaches a text message to a timer for later display.

Parameters:
message - to display with timer.
Method Detail

reset

public void reset()
Reset the start time (same as creating a new object)


stop

public String stop()
Sets the end time

Returns:
returns the formatted elapsed seconds

stop

public String stop(String msg)
Sets the end time and returns the elapsed time and message.

Parameters:
msg - to display with timer output.
Returns:
returns the formatted elapsed seconds with message.

print

public void print()
Stop timer and print result to stdout


print

public void print(String msg)
Stop timer and print result to stdout.

Parameters:
msg - additional message to print

println

public void println(String msg)
Stop timer and print result to stdout including a carriage-return

Parameters:
msg - additional message to print

println

public void println()
Stop timer and print result to stdout including a carriage-return


secondsElapsed

public float secondsElapsed()
Stops timer if running and returns seconds elapsed since creation or last reset

Returns:
seconds of course

toString

public String toString()
Returns a string with attached message and elapsed seconds in brackets.

Returns:
a string representation of the elapsed time.
See Also:
Object.toString()


Copyright © 2005 Paul Marrington http://library.marringtons.com