uk.org.skeet.jbench
Interface BenchTask

All Known Implementing Classes:
ListFill, SimpleTask, ArrayFill, ListSort

public interface BenchTask

Interface to be implemented by all tasks. All implementations should have a public no-arg constructor, as this is what JBench will call to create an instance. Configuration parameters will be set using setXXX methods supplied by the implementation - these are detected automatically by JBench, which attempts to find an appropriate method for each configuration parameter specified.

Note that instance variables should be used to store configuration information, as a task may be configured in two different ways for two different sets of tests within the same benchmark.

After the configuration has been set, checkConfiguration is called. If that doesn't throw an exception, the following sequence of events happens for as many iterations as the global JBench configuration states:

prepareTest is called to prepare for the next test run.
The time is checked.
runTest is called to run the test itself.
The length of time taken is calculated.
checkResults is called to make sure that the test has actually done what it should have done.

If checkConfiguration throws an exception, the entire benchmark may or may not be abandoned, depending on how JBench itself has been configured.

If checkResults ever fails (ie throws an exception), the entire set of test results for this task are discarded, and the exception message is reported.


Method Summary
 void checkConfiguration()
          Checks that the configuration supplied is valid.
 void checkResults()
          Checks that the test completed successfully.
 java.lang.String getDescription()
          Returns a detailed description of the task, including any pertinent configuration information.
 void prepareTest()
          Prepares the task for a test.
 void runTest()
          Runs a test.
 

Method Detail

checkConfiguration

public void checkConfiguration()
                        throws ConfigurationException
Checks that the configuration supplied is valid. If it isn't, the implementation should throw a TaskException with an appropriate message.
Throws:
ConfigurationException - if the configuration specified is incomplete or invalid.

prepareTest

public void prepareTest()
                 throws TaskException
Prepares the task for a test. For instance in a sort task, this may populate the collection to be sorted. This method is called before runTest for each test.
Throws:
TaskException - if the preparation failed.

runTest

public void runTest()
             throws TaskException
Runs a test. This is the method which is timed for result purposes. This should not include any preparation or result checking unless the time reported deliberately requires it.
Throws:
TaskException - if the test failed to complete normally.

checkResults

public void checkResults()
                  throws TaskException
Checks that the test completed successfully. For instance in a sort task, this may check that the results ended up correctly sorted. This method is called after runTest for each test.
Throws:
TaskException - if the test failed.

getDescription

public java.lang.String getDescription()
Returns a detailed description of the task, including any pertinent configuration information. This method is only called after checkConfiguration has returned without throwing an exception, so implementations may rely on all configuration information being available.