Xit*_*rum 4 java microbenchmark jmh
我目前的设置:
public void launchBenchmark() throws Exception {
Options opt = new OptionsBuilder()
.include(this.getClass().getName())
.mode(Mode.Throughput) //Calculate number of operations in a time unit.
.mode(Mode.AverageTime) //Calculate an average running time per operation
.timeUnit(TimeUnit.MILLISECONDS)
.warmupIterations(1)
.measurementIterations(30)
.threads(Runtime.getRuntime().availableProcessors())
.forks(1)
.shouldFailOnError(true)
.shouldDoGC(true)
.build();
new Runner(opt).run();
}
Run Code Online (Sandbox Code Playgroud)
如何知道/控制(如果可能)每个基准测试执行的操作数量?
设置暖启时间和测量迭代时间是否重要?
谢谢.
您无法控制每次迭代的操作数.JMH的重点是正确测量这个数字.
您可以使用注释配置预热:
@Warmup(iterations = 10, time = 500, timeUnit = MILLISECONDS)
Run Code Online (Sandbox Code Playgroud)
测量依据:
@Measurement(iterations = 200, time = 200, timeUnit = MILLISECONDS)
Run Code Online (Sandbox Code Playgroud)
只需为您的用例设置适当的值