Package ej.benchmark

Class 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.
    The test (step 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 the emptyRun() 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 by getRunTime().

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static 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.
      protected static long RUN_TIME
      Defines the test run time (in milliseconds)
    • Constructor Summary

      Constructors 
      Constructor Description
      BenchTest()  
    • 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
    • Constructor Detail

      • BenchTest

        public BenchTest()
    • 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 by getRunTime().

        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.