controlling the exact number of times a method is called

Aleksey Shipilev aleksey.shipilev at oracle.com
Thu Jun 26 21:40:59 UTC 2014


Hi,

On 06/25/2014 12:00 AM, Ymo Lists wrote:
> I am trying to benchmark a hashmap and i need to control how many
> times the method being benchmarked is being called. I also need to
> get the percentile distribution from the result. For that i am using
> @BenchmarkMode(Mode.SampleTime). I am also using using
> measurementBatchSize api but in the results i see that the number of
> samples is different.
> 
> 1) How did that happen?

What did happen? Trying to decipher: you wanted the number of samples to
be equal to batch size? Batch size is the number of @B method calls per
batch, not per iteration; batching makes sense only when you measure the
individual operations, e.g. in SingleShot mode.

In other modes, batching is not working. It might be a good idea to
extend batching to SampleTime, so that we can time the entire batch, hm...

> 2) How can i make sure i know exactly how
> many times the method will be called 

You can't know this for sure, unless you use SingleShot mode where there
is exactly one batch is going to be executed.

> 3) How can get access to the raw
> data of when the method was called and the actual time it took for
> each call.

*Each* call is only measured with SingleShot mode. SampleTime mode
*samples* the execution times, so "each" is out of reach. You can
unsafely access the raw SampleBuffer through the Java API, or use JSON
output format to dump the raw samples.

> The code and results are in 
> https://gist.github.com/ymolists/7b5581d48d4e1d4f1054


Thanks,
-Aleksey.

P.S. This would probably help to understand that you can't directly
measure the nanoscale events:
  http://shipilev.net/blog/2014/nanotrusting-nanotime/


More information about the jmh-dev mailing list