Overriding benchmark method metadata does not work

Jozef Hartinger jozefhartinger at gmail.com
Tue Mar 17 08:40:50 UTC 2015


Hi all,

I have a simple benchmark like this:

public class Benchmark1 {

     private static final int[] ARRAY = new int[1 << 20];

     @Benchmark
     @BenchmarkMode(Mode.Throughput)
     @Measurement(batchSize = 1 << 2, iterations = 5)
     public boolean run() {
         Arrays.sort(getData());
         return true;
     }

     protected int[] getData() {
         return ARRAY;
     }
}

This is a base class. Subclasses exist which simply override getData() 
and provide different data sets. For a certain subclass I also need to 
change the batch size. I started with:

public class Benchmark2 extends Benchmark1 {

     @Measurement(batchSize = 1 << 5, iterations = 5)
     @Override
     public boolean run() {
         return super.run();
     }

     @Override
     protected int[] getData() {
         return super.getData();
     }
}

That is overriding the run method and adding @Measurement with a 
different value. That does not seem to have any effect. Then I tried:

public class Benchmark2 extends Benchmark1 {

     @Benchmark
     @BenchmarkMode(Mode.Throughput)
     @Measurement(batchSize = 1 << 5, iterations = 5)
     @Override
     public boolean run() {
         return super.run();
     }

     @Override
     protected int[] getData() {
         return super.getData();
     }
}

but then I get:
"Benchmark1.java:[33,20] Internal error: multiple methods per @Group, 
but not all methods have @Group"

I think that if a method is overriden, the metadata present on the 
overriding method should override the original metadata. WDYT?

Jozef


More information about the jmh-dev mailing list