如果我有
@Benchmark
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void foo() {
for (int i = 0; i < 1000; i++) {
System.out.println(i);
}
}它在300微秒内运行。
问:有没有办法获得价值为300的int/long?
发布于 2022-06-12 21:03:43
您可以编程运行基准测试并访问其结果:
public class BenchmarkRunner {
public static void main(String[] args) throws Exception {
Options opt = new OptionsBuilder()
.include(YourBenchmark.class.getSimpleName())
.warmupIterations(10)
.warmupTime(TimeValue.seconds(1))
.measurementIterations(10)
.measurementTime(TimeValue.seconds(2))
.forks(5)
.shouldFailOnError(true)
.build();
Collection<RunResult> runResults = new Runner(opt).run();
runResults.forEach(runResult -> {
Result primaryResult = runResult.getPrimaryResult();
double score = primaryResult.getScore(); // <-- here's the score of your benchmark
});
}
}https://stackoverflow.com/questions/72589730
复制相似问题