use*_*599 3 java benchmarking jmh
有一个错误,JMH没有把我的班级提升到基准.
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" };
}
}
Run Code Online (Sandbox Code Playgroud)
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());
}
}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
不包括:org.sample.MyBenchmark.testMethod,与com.stecurra.benchmark.strategy.EventRunner不匹配没有匹配的基准测试.拼写错误的正则表达式?使用-v表示详细输出.
如何更改我的正则表达式有效?
谢谢
确保您实际编译了项目,让JMH注释处理器运行并为您生成基准列表.从你在那里的消息,很明显,它EventRunner.test没有进入基准列表.
我们在这里,其他花絮:
@GenerateMicroBenchmark方法内部的时间不是你想要的.相反,您需要让JMH为您进行定时测量.参见例如相关的JMH样品.