Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMH difference between Sample and SingleShot

Tags:

java

jmh

What's the difference between setting Mode.Sample and Mode.SingleShot together with measurementIterations set to large number? Is it effectively the same or is there some quantitive difference between the two modes?

like image 680
Dan Avatar asked Dec 10 '22 18:12

Dan


1 Answers

But... Javadoc states the difference quite specifically?

Sample time: samples the time for each operation.

Runs by continuously calling {@link Benchmark} methods, and randomly samples the time needed for the call. This mode automatically adjusts the sampling frequency, but may omit some pauses which missed the sampling measurement. This mode is time-based, and it will run until the iteration time expires.

And:

Single shot time: measures the time for a single operation.

Runs by calling {@link Benchmark} once and measuring its time. This mode is useful to estimate the "cold" performance when you don't want to hide the warmup invocations, or if you want to see the progress from call to call, or you want to record every single sample. This mode is work-based, and will run only for a single invocation of {@link Benchmark} method.

Caveats for this mode include:

  • More warmup/measurement iterations are generally required.
  • Timers overhead might be significant if benchmarks are small; switch to {@link #SampleTime} mode if that is a problem.
like image 154
Aleksey Shipilev Avatar answered Dec 21 '22 07:12

Aleksey Shipilev