TLD
TLD

Reputation: 8135

Control number of operation per iteration JMH

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.

Upvotes: 11

Views: 7270

Answers (1)

Svetlin Zarev
Svetlin Zarev

Reputation: 15673

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

Upvotes: 19

Related Questions