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
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:
@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.