Using PerformanceTestResult helpers
A performance helper suite of classes was introduced, allowing shootouts to be simpler:
Callable<Void> exprCallable = new Callable<Void>() {
@Override
public Void call() throws Exception {
expression.value(context);
return null;
}
};
Callable<Void> javaCallable = new Callable<Void>() {
@Override
public Void call() throws Exception {
function(x);
return null;
}
};
PerformanceTestCallable exprPerfCallable = new PerformanceTestCallable("Expression "
+ expression.getExpressionString(), exprCallable);
PerformanceTestCallable javaPerfCallable = new PerformanceTestCallable("Java", javaCallable);
PerformanceTestResult compareResult = PerformanceTestHelper.compare(20, 200000, exprPerfCallable,
javaPerfCallable);
compareResult.printResults();
The API is com.splwg.base.api.testers.performance.PerformanceTestHelper:
public static PerformanceTestResult compare(int warmups, int reps, PerformanceTestCallable... callables)
throws Exception {
Each of the performance callables is treated the same. It gets a series of warmup executions to
populate caches, and to allow hotspot JVM optimizations of any methods. Then the
accurate system nano timing (for example, System.nanoTime()) is called
around the loop of the given number of reps.
