In my jmh class, I'm using
@BenchmarkMode(Mode.SampleTime)
@Measurement(iterations = 10)
@Threads(value = 10)
at the class level.
And in the results, for the cnt
column, I see 132, for one method and 155 for another. I was assuming cnt
might mean number of executions but those numbers don't match what I'm expecting.
Shouldn't number of executions be 10 (threads) * 10 (iterations) = 100?
Frankly, I do not know how cnt
is calculated when benchmark mode is Mode.SampleTime
, but I want to clarify a couple of things.
First of all, benchmarking with JMH is concurrent in nature. The @Threads
annotation specifies that ten threads should be allocated to run your benchmark (default is 4). If you do not specify @Threads
, it will allocate only one thread for benchmarking.
Secondly, if you change your mode to Mode.Throughput
and add @Fork(value = 5)
annotation, you will see cnt
column with value 50. Because your benchmark will be executed in 5 forks and each fork will have 10 iterations. Simply, cnt
is forkNumber * measurementIterations
for this case.
Finally, this calculation changes when mode is Mode.SampleTime
or when you use @Param
annotation (cnt = numOfParams * forkNumber * measurementIterations
). For example, if you run different benchmark with same annotations (Mode.SampleTime
), you'll see different numbers on cnt
column.
I hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With