Control number of operation per iteration JMH

java, jmh, microbenchmark

Solution

You cannot control the number of operations per iteration. The whole point of JMH is to correctly measure that number.

You can configure the warmup using the annotation:

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

And the measurement by:

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

Just set the appropriate values for your use case

Problem

My current setup: ``` 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(); } ``` How can I know/control (if possible) the number of operations is performed per benchmark ? And is it important to set warmUp time and measurementIteration time? Thank you.

Original source