ch.claudio.lib
Class Timer

java.lang.Object
  extended by ch.claudio.lib.Timer

public class Timer
extends java.lang.Object

Class for measuring time.

Note: Elapsed time is measured, including time waiting for I/O or because the CPU is allocated to another process.

Note: If used in recursive procedures with a depth>100 this class will cause ArrayBoundExctions.

Version:
$Id: Timer.java 148 2006-09-14 20:52:32Z claudio $
Author:
Claudio Nieder

Copyright (C) 2006 Claudio Nieder <private@claudio.ch>, CH-8610 Uster

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA


Constructor Summary
Timer()
           
 
Method Summary
static void dumpCollect()
          Dump all collected data.
 long getCount()
           
 long getDuration()
           
 long getMax()
          Return largest duration (time between a start and the following stop) for this timer.
 long getMean()
           
 long getMin()
          Return smallest duration (time between a start and the following stop) for this timer.
static java.util.Collection<Timer> getTimers()
          Return all timers in use.
 long getVariance()
           
static void main(java.lang.String[] args)
          Print license.
static void printSummary()
          Print a summary of all timers to stdout
static void printSummary(java.io.PrintWriter out)
          Print a summary of all timers.
static Timer start(java.lang.Object o)
          Find timer identified by object or and start it.
static void startCollect(int size)
          Create an array and collect all start and stop events.
 void stop()
          Stop timer.
static void stopCollect()
          Stop the collection of timer events.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Timer

public Timer()
Method Detail

startCollect

public static void startCollect(int size)
Create an array and collect all start and stop events. If the size is not chosen large enough out of bound exceptions will occur.

Parameters:
size - of the array

stopCollect

public static void stopCollect()
Stop the collection of timer events. The data is deleted.


dumpCollect

public static void dumpCollect()
Dump all collected data. Must be executed before a stopCollect.


start

public static Timer start(java.lang.Object o)
Find timer identified by object or and start it.

Parameters:
o - Typically a string used to distinguish this timer from a different one.
Returns:
started timer

stop

public void stop()
Stop timer. Use the getters to access single values or


getMax

public long getMax()
Return largest duration (time between a start and the following stop) for this timer.

Returns:
the max

getMin

public long getMin()
Return smallest duration (time between a start and the following stop) for this timer.

Returns:
the min

getDuration

public long getDuration()
Returns:
the duration (time between a start and the following stop) of last measurement

getCount

public long getCount()
Returns:
the number of measurements done with this timer

getMean

public long getMean()
Returns:
the mean duration (time between a start and the following stop)

getVariance

public long getVariance()
Returns:
the variance in duration (time between a start and the following stop)

getTimers

public static java.util.Collection<Timer> getTimers()
Return all timers in use.

Returns:
timer collection

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

printSummary

public static void printSummary(java.io.PrintWriter out)
Print a summary of all timers.

Parameters:
out - destination

printSummary

public static void printSummary()
Print a summary of all timers to stdout


main

public static void main(java.lang.String[] args)
Print license.

Parameters:
args - ignored