util
Class Launcher

java.lang.Object
  extended by util.Launcher

public class Launcher
extends Object

Resets state when multiple runs of the same piece of code are executed.


Method Summary
 void addStats(Statistics stat)
          Adds statistics to current run
 long elapsedTime(boolean withoutGc)
          Returns the wall-time of the most recently completed run with or without garbage collection time included
static Launcher getLauncher()
           
 Random getRandom(int seed)
          Returns the random number generator for this run
 List<Statistics> getStatistics()
           
 boolean isFirstRun()
           
 void onRestart(Runnable callback)
          Adds a callback to be called when launcher is reset.
 void reset()
          Resets the launcher to its initial configuration in preparation for the next run.
 void startTiming()
          Marks beginning of timed section.
 void stopTiming()
          Marks end of timed section.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

startTiming

public void startTiming()
Marks beginning of timed section. If there are multiple calls to this method within the same run, honor the latest call. This method also performs a full garbage collection.


stopTiming

public void stopTiming()
Marks end of timed section. If there are multiple calls to this method within the same run, honor the earliest call.


isFirstRun

public boolean isFirstRun()
Returns:
true if this is the first run

elapsedTime

public long elapsedTime(boolean withoutGc)
Returns the wall-time of the most recently completed run with or without garbage collection time included

Parameters:
withoutGc - true if garbage collection time should be excluded from result
Returns:
wall-time in milliseconds of the run

reset

public void reset()
Resets the launcher to its initial configuration in preparation for the next run. All previously accumulated statistics will be cleared.


getStatistics

public List<Statistics> getStatistics()
Returns:
the accumulated statistics for the most recently completed run

onRestart

public void onRestart(Runnable callback)
Adds a callback to be called when launcher is reset.

Parameters:
callback - callback to called on reset

addStats

public void addStats(Statistics stat)
Adds statistics to current run

Parameters:
stat - the statistics to add

getRandom

public Random getRandom(int seed)
Returns the random number generator for this run

Parameters:
seed - the random number generator seed
Returns:
a random number generator

getLauncher

public static Launcher getLauncher()
Returns:
an instance of the launcher