jmh 0.6. I have jmh-core, jmh-generator-annprocess, jmh-generator-reflection as dependencies.
First, documentation is poor, unfortunately. For one, I use gradle, not maven, so using the maven archetype is not an option.
Second, I want to use the Java API, not the command line.
My very simple code is that:
public final class TestBenchmark
{
private static final int COUNT = 100_000;
private static final List<Integer> LIST = new ArrayList<>();
static {
for (int i = 0; i < COUNT; i++)
LIST.add(i);
}
@GenerateMicroBenchmark
public void foreachLoop()
{
int dummy;
for (final int i: LIST)
dummy = i;
}
@GenerateMicroBenchmark
public void forLoop()
{
int dummy;
final int size = LIST.size();
for (int i = 0; i < size; i++)
dummy = LIST.get(i);
}
public static void main(final String... args)
throws RunnerException
{
final Options options = new OptionsBuilder()
.forks(1)
.warmupIterations(1)
.measurementIterations(20)
.verbosity(VerboseMode.EXTRA)
.build();
new Runner(options).run();
}
}
As I have no .include()
, it means .*
as a regex therefore all benchmarks. This is the only class I have in my project.
But no: "no benchmarks found".
So, as a last resort I tried and created the META-INF/MicroBenchmarks
file as suggested in other places; content, the name of the class:
com.github.parboiled1.grappa.TestBenchmark
but it doesn't work either:
Exception in thread "main" java.lang.IllegalStateException: Mismatched format for the line: com.github.parboiled1.grappa.TestBenchmark
and the format of this file is, of course, not documented.
But I don't want to use this file to start with; I want to specify the list of classes to run.
How do I do that?