JMH not picking up class to benchmark

6.5k views Asked by At

Having an error whereby JMH is not picking up my class to benchmark.

package com.stecurran.jmh.entry;

import org.openjdk.jmh.Main;

public class JmhRunner {

    private static final String TEST = "com.stecurra.benchmark.strategy.EventRunner";

    public static void main(String[] args) {

        Main.main(getArguments(TEST, 5, 5000, 1));
    }

    private static String[] getArguments(String className, int nRuns, int runForMilliseconds, int nThreads) {
        return new String[] { className, "-i", "" + nRuns, "-r", runForMilliseconds + "ms", "-t", "" + nThreads, "-w", "5000ms", "-wi", "3", "-v" };
    }

}

Where EventRunner contains:

    package com.stecurra.benchmark.strategy;

import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
import org.openjdk.jmh.annotations.Mode;



@BenchmarkMode(Mode.AverageTime)
public class EventRunner {

    @GenerateMicroBenchmark
    public void runTest(){

        TimeStore.start = System.nanoTime();


        // FacebookRetriever fbCal = FacebookRetriever.getInstance();
        GoogleRetriever gCal = GoogleRetriever.getInstance();

        CalendarService cs = new CalendarService(gCal);

        for (SimpleEvent simpleEvent : cs.getEvents()) {
            System.out.println(simpleEvent);
        }

        TimeStore.end = System.nanoTime();

        System.out.println(TimeStore.getTime());        

    }

}

And I get this error:

Excluding: org.sample.MyBenchmark.testMethod, does not match com.stecurra.benchmark.strategy.EventRunner No matching benchmarks. Miss-spelled regexp? Use -v for verbose output.

How can I change my regex to be valid?

Thanks

1

There are 1 answers

2
Aleksey Shipilev On BEST ANSWER

Make sure you actually compiled the project, letting JMH annotation processors to run and generate the benchmark list for you. From the message you have there, it is apparent the EventRunner.test had not make it to the benchmark list.

While we are at it, other tidbits:

  1. Hijacking the JMH Main might be the easy way into the running the benchmark, but we have better Java API for the use cases like that.
  2. Measuring time and especially printing out the time inside for @GenerateMicroBenchmark method is not something you want probably. Instead, you need to let JMH to do timing measurements for you. See e.g. relevant JMH sample.
  3. After you eliminate the printout, you will need to feed the values you got into the blackhole, this the relevant JMH sample.