Package ej.benchmark
Class BenchTest
- java.lang.Object
-
- ej.benchmark.BenchTest
-
public abstract class BenchTest extends Object
Represents a test to bench.A test has three steps:
pre(): Before launching the test, the test fields and environment must be initialized during this step. This preparation time is not accounted for.run(): The test itself.post(): After the test execution, this step is called to clean the test environment.
run()) can contain for any reasons some code which must not be accounted for. In this case, this peace of code must be ran again in theemptyRun()in order to remove this time.To have good results, the test must be executed several times. To determinate the available number of iterations, a calibration step is performed during a time defined by
getCalibrationTime(). In a second time, this number of iterations is used to reach the bench time specified bygetRunTime().
-
-
Field Summary
Fields Modifier and Type Field Description protected static longCALIBRATION_TIMEDefines the default time (in milliseconds) to calibrate the number of iterations the test must be ran to reach the expected run time.protected static longRUN_TIMEDefines the test run time (in milliseconds)
-
Constructor Summary
Constructors Constructor Description BenchTest()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidemptyRun()Called to remove from full test some time which must not be accounted for in bench results.protected longgetCalibrationTime()Gets the time to calibrate the number of iterations the test must be ran to reach the expected run time.intgetNumberOfIterations()Gets the number of iterations the bench must be ran to reach the bench time specified bygetRunTime().protected longgetRunTime()Gets the time the test must run to perform the bench.voidpost()Called to clean bench test environment after running the test.voidpre()Called to initialize bench test fields and environment before running the test.abstract voidrun()Run the full test.
-
-
-
Field Detail
-
CALIBRATION_TIME
protected static final long CALIBRATION_TIME
Defines the default time (in milliseconds) to calibrate the number of iterations the test must be ran to reach the expected run time.- See Also:
- Constant Field Values
-
RUN_TIME
protected static final long RUN_TIME
Defines the test run time (in milliseconds)- See Also:
- Constant Field Values
-
-
Method Detail
-
getCalibrationTime
protected long getCalibrationTime()
Gets the time to calibrate the number of iterations the test must be ran to reach the expected run time.Default returned value is
CALIBRATION_TIME.- Returns:
- a time in milliseconds
-
getRunTime
protected long getRunTime()
Gets the time the test must run to perform the bench.Default returned value is
RUN_TIME.- Returns:
- a time in milliseconds
-
getNumberOfIterations
public int getNumberOfIterations()
Gets the number of iterations the bench must be ran to reach the bench time specified bygetRunTime().This method can be overrided to force to use a specific number of iterations without taking in consideration
getRunTime().- Returns:
- a number of iterations (at least 1 iteration).
-
pre
public void pre()
Called to initialize bench test fields and environment before running the test.By default there is noting to initialize.
-
post
public void post()
Called to clean bench test environment after running the test.By default there is noting to clean.
-
run
public abstract void run()
Run the full test.
-
emptyRun
public void emptyRun()
Called to remove from full test some time which must not be accounted for in bench results.
-
-