com.twitter.common.util
Class Timer

java.lang.Object
  extended by com.twitter.common.util.Timer

public final class Timer
extends Object

A utility for timing blocks of code.

TODO(John Sirois): consider instead: Pair doTimed(ExceptionalSupplier timedWork) throws E or a subinterface of Command/Closure/Supplier/Function that exposes a timing method as other ways to factor in timing.


Method Summary
static
<E extends Exception>
void
doTimed(SlidingStats stat, ExceptionalCommand<E> timedWork)
          Times the block of code encapsulated by timedWork recoding the result in stat.
static
<T,E extends Exception>
T
doTimed(SlidingStats stat, ExceptionalSupplier<T,E> timedWork)
          Times the block of code encapsulated by timedWork recoding the result in stat.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

doTimed

public static <E extends Exception> void doTimed(SlidingStats stat,
                                                 ExceptionalCommand<E> timedWork)
                    throws E extends Exception
Times the block of code encapsulated by timedWork recoding the result in stat.

Type Parameters:
E - the type of exception timedWork may throw
Parameters:
stat - the stat to record the timing with
timedWork - the code to time
Throws:
E - if timedWork throws
E extends Exception

doTimed

public static <T,E extends Exception> T doTimed(SlidingStats stat,
                                                ExceptionalSupplier<T,E> timedWork)
                 throws E extends Exception
Times the block of code encapsulated by timedWork recoding the result in stat.

Type Parameters:
T - the type of result timedWork returns
E - the type of exception timedWork may throw
Parameters:
stat - the stat to record the timing with
timedWork - the code to time
Returns:
the result of timedWork if it completes normally
Throws:
E - if timedWork throws
E extends Exception