Java – jmh does not pick up classes for benchmarking
There is a mistake, jmh did not promote my class to the 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" }; } }
Location of eventrunner:
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()); } }
I received this error:
Excluding: org sample. MyBenchmark. Testmethod, and com stecurra. benchmark. strategy. Eventrunner does not match. There is no matching benchmark Misspelled regular expressions? Use - V for verbose output
How do I change the validity of my regular expression?
thank you
Solution
Make sure you actually compiled the project, run the jmh annotation processor, and generate the benchmark list for you From the news that you are there, it is obvious that eventrunner Test does not enter the benchmark list
Here we are, other highlights:
>Hijacking jmh main may be a simple way to run benchmarks, but we have a better Java API for such use cases. > Measuring time, especially the internal time of printing @ generatemicrobenchmark method, may not be what you want Instead, you need jmh to make timing measurements for you See, for example, relevant jmh sample. > After eliminating the printout, you need to input the entered value into the black hole, this the relevant jmh sample