utilities
Class UTimer

java.lang.Object
  |
  +--utilities.UTimer

public class UTimer
extends java.lang.Object


Constructor Summary
UTimer(java.lang.String n)
          constructor for a named timer.
UTimer(java.lang.String n, int window)
          constructor for a windowed timer.
 
Method Summary
 void action()
          the static time function will time whatever this function does.
static void clearTimer(java.lang.String s)
          removes the specified timer from the global timer list.
 double getAverage()
          returns the average of all timing.
 int getCount()
          returns the number of times collected.
 long getTime()
          returns the result of timing.
static UTimer getTimer(java.lang.String s)
          returns a UTimer with the specified name.
 int getWindow()
          returns the size of the window used.
 boolean isWindowed()
          returns whether the timer is windowed.
 void resetTimer()
          Resets the timer.
 void resetWindow()
          clears the window of all data.
 void setWindowed(boolean b, int w)
          Sets whether the timer is windowed.
 void startTimer()
          Starts the timer.
 long stopTimer()
          Stops the timer.
static long time(int count, UTimer t)
          times something using whatever windowing setting the UTimer already has.
static long time(int count, UTimer t, boolean windowed)
          will time the specified timer's action, for count times, with the given windowed setting.
static long time(UTimer t)
          times the specified timer's action once.
 java.lang.String toString()
          returns a human readable display of the timer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UTimer

public UTimer(java.lang.String n)
constructor for a named timer. This will not create a windowed timer.
Parameters:
n - the name of the timer.

UTimer

public UTimer(java.lang.String n,
              int window)
constructor for a windowed timer. This creates a UTimer with a specified name, and a specified window.
Parameters:
n - the name of the timer.
window - the size of the window.
See Also:
setWindowed(boolean, int)
Method Detail

getTimer

public static UTimer getTimer(java.lang.String s)
returns a UTimer with the specified name. If the timer doesn't exist, it'll create one.
Parameters:
s - the name of the timer to get.

clearTimer

public static void clearTimer(java.lang.String s)
removes the specified timer from the global timer list.
Parameters:
s - the name of the timer to dispense with.

time

public static long time(int count,
                        UTimer t,
                        boolean windowed)
will time the specified timer's action, for count times, with the given windowed setting. This is the simplest way I could come up with to do this, without having functions at first class objects. Here is some sample code that I use to time stuff in BetterArea: UTimer.time(100, new UTimer("findArea with partials") { public void action() { b.setDepth(temp); temparea = b.findArea(); b.flushCache(); b.printcachestats = false; } }, true); This code creates an anonymous UTimer class with an action function that calls the BetterArea's find area function. Some workarounds are necessary to use variables from the local scope outside of the class definition; the need to be final and there are some other wierdnesses. For more detail see BetterArea.main()
Parameters:
count - the number of times to time the action.
t - the UTimer to use - it's recommended that you fill in that timer's action function, or not much will happen.
whether - to use windowing or not.
See Also:
BetterArea.main(java.lang.String[]), setWindowed(boolean, int), action()

time

public static long time(int count,
                        UTimer t)
times something using whatever windowing setting the UTimer already has.
Parameters:
count - the number of times to run the action.
t - the timer to use.
See Also:
time(int,UTimer,boolean)

time

public static long time(UTimer t)
times the specified timer's action once.
Parameters:
t - the UTimer to use.
See Also:
#time(int,Timer,boolean)

isWindowed

public boolean isWindowed()
returns whether the timer is windowed.

setWindowed

public void setWindowed(boolean b,
                        int w)
Sets whether the timer is windowed. This idea is stolen from Bryan's Observer class - the window is the size of the array in which to store data. Up to w datapoints will be stored, and then the array counter will loop around and start filling the beginning of the array again. If the timer is not windowed, only one time will be stored. Successive calls to startTimer and stopTimer without resetting the timer will just add on to the time. If it is windowed, they will increment the array counter.
Parameters:
b - whether the UTimer should use windowing.
w - the size of the window to use.

getWindow

public int getWindow()
returns the size of the window used.

resetWindow

public void resetWindow()
clears the window of all data.

startTimer

public void startTimer()
Starts the timer.

stopTimer

public long stopTimer()
Stops the timer.

resetTimer

public void resetTimer()
Resets the timer. If windowing is enabled, all data is cleared.

getTime

public long getTime()
returns the result of timing. If windowing is enabled, this returns the results of the most recent timing, and if not, returns the total of all timing since the last reset. If no timing has occured, returns 0.

getAverage

public double getAverage()
returns the average of all timing. If windowing is enabled, this will compute an average, and if not, it will just return the results of getTime().

getCount

public int getCount()
returns the number of times collected.

toString

public java.lang.String toString()
returns a human readable display of the timer. You should be able to just print this and it will show you what you want.
Overrides:
toString in class java.lang.Object

action

public void action()
the static time function will time whatever this function does. You should override it if you want to use the timer this way. The suggested way of doing this is using an anonymous class.
See Also:
time(int, utilities.UTimer, boolean)