New benchmark modes

Nitsan Wakart nitsanw at azulsystems.com
Wed Nov 16 12:56:47 UTC 2016


 > See how "targetSamples" is calculated in the generated stub.
Yes:
   int targetSamples = (int) (control.getDuration(TimeUnit.MILLISECONDS) 
* 20); // at max, 20 timestamps per millisecond

The generated measurement code (commented to see if I understand the 
intention):
   int rnd = (int)System.nanoTime();
   int rndMask = this.startRndMask; // startRndMask is initially 0
   long time = 0;
   int currentStride = 0;
   do {
     rnd = (rnd * 1664525 + 1013904223); // magic random number, I 
assume Shipilev did the maths, but wish he'd leave a comment
     boolean sample = (rnd & rndMask) == 0; // this is initially true 
until we hit "too many samples" below
     if (sample) {
         time = System.nanoTime();
     }
     for (int b = 0; b < batchSize; b++) {
         if (control.volatileSpoiler) return;
         l_jmhsample_02_benchmarkmodes0_0.measureSamples();
     }
     if (sample) {
         buffer.add((System.nanoTime() - time) / opsPerInv);
         if (currentStride++ > targetSamples) { // too many samples
             buffer.half(); // half the sample counts, since we'll be 
sampling half as much from now on
             currentStride = 0;
             rndMask = (rndMask << 1) + 1; // block another bit
         }
     }
     operations++;
   } while(!control.isDone);
   this.startRndMask = Math.max(startRndMask, rndMask);

This hits on the question of how to deliver parameters to benchmark 
modes that has not been tackled to date. Which is also, I'm guessing, 
what you mean by this:
 > The only troubling thing here is that you need to pass in the rate 
parameter somehow...
Is it reasonable to add an annotation parameter here? The command line 
format can follow the same convention as profiler parameterization 
(e.g.:"-bm sample:targetSamplesPerMs=20")


More information about the jmh-dev mailing list