控制每次迭代的操作数 JMH

Control number of operation per iteration 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();
}

如何know/control(如果可能)每个基准执行的操作数?

设置预热时间和测量迭代时间重要吗?

谢谢。

您无法控制每次迭代的操作数。 JMH 的重点是正确地测量那个数字

您可以使用注释配置预热:

@Warmup(iterations = 10, time = 500, timeUnit = MILLISECONDS)

测量方式:

@Measurement(iterations = 200, time = 200, timeUnit = MILLISECONDS)

只需为您的用例设置适当的值