uk.org.skeet.jbench.tasks
Class SimpleTask

java.lang.Object
  |
  +--uk.org.skeet.jbench.tasks.SimpleTask
All Implemented Interfaces:
BenchTask
Direct Known Subclasses:
DoubleAdditionTask, FloatAdditionTask, InlineTask, ListTraverse, MultipleListTraverse, PreparedStatementTask, ProxyTask, ReflectionTask

public abstract class SimpleTask
extends java.lang.Object
implements BenchTask

Abstract class to make simple tasks easier to write. There are default no-op implementations for prepareTest and checkResults, getDescription returns something reasonable by default, and there's a single field, size, which is checked by default to be positive.

Subclasses are expected to write runTest methods of the form: public void runTest() { long size = getSize(); for (long i=0; i < size; i++) { // insert code here } }

Quite a few tests of this form are useful, for instance testing the difference between StringBuffer.append() and String concatenation, where not a lot needs to be done first, but the test needs some kind of associated size. In some cases the size may be used for sizing a single test (eg the size of a vector to sort), in others it may be used for repeating a very short test several times (eg adding two floats or adding two doubles).


Constructor Summary
SimpleTask()
           
 
Method Summary
 void checkConfiguration()
          Checks that we have a positive size
 void checkResults()
          Simple no-op implementation of checkResults.
 java.lang.String getDescription()
          Default description which gives the name of the actual class and the number of iterations.
protected  long getSize()
          Returns the number of size per test
 void prepareTest()
          Simple no-op implementation of prepareTest.
 void setSize(long value)
          Sets the number of size per test
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface uk.org.skeet.jbench.BenchTask
runTest
 

Constructor Detail

SimpleTask

public SimpleTask()
Method Detail

setSize

public void setSize(long value)
Sets the number of size per test

getSize

protected long getSize()
Returns the number of size per test

checkConfiguration

public void checkConfiguration()
                        throws ConfigurationException
Checks that we have a positive size
Specified by:
checkConfiguration in interface BenchTask
Following copied from interface: uk.org.skeet.jbench.BenchTask
Throws:
ConfigurationException - if the configuration specified is incomplete or invalid.

prepareTest

public void prepareTest()
                 throws TaskException
Simple no-op implementation of prepareTest.
Specified by:
prepareTest in interface BenchTask
Following copied from interface: uk.org.skeet.jbench.BenchTask
Throws:
TaskException - if the preparation failed.

checkResults

public void checkResults()
                  throws TaskException
Simple no-op implementation of checkResults.
Specified by:
checkResults in interface BenchTask
Following copied from interface: uk.org.skeet.jbench.BenchTask
Throws:
TaskException - if the test failed.

getDescription

public java.lang.String getDescription()
Default description which gives the name of the actual class and the number of iterations.
Specified by:
getDescription in interface BenchTask