RuntimeWorkerInstrument extends WorkerInstrument { @VisibleForTesting static long calculateTargetReps(long reps, long nanos, long targetNanos, double gaussian) { double targetReps = (((double) reps) / nanos) * targetNanos; return Math.max(1L, Math.round((gaussian * (targetReps / 5)) + targetReps)); } RuntimeWorkerInstrument(
      Object benchmark,
      Method method,
      Random random,
      Ticker ticker,
      Map<String, String> workerOptions); @Override void bootstrap(); @Override void preMeasure(boolean inWarmup); @Override void dryRun(); @Override Iterable<Measurement> measure();  }
@Test public void testCalculateTargetReps_tinyBenchmark() { ShortDuration oneCycle = ShortDuration.of(new BigDecimal("2.0e-10"), SECONDS); long targetReps = calculateTargetReps( INITIAL_REPS, oneCycle.times(INITIAL_REPS).to(NANOSECONDS), TIMING_INTERVAL.to(NANOSECONDS), 0.0); long expectedReps = TIMING_INTERVAL.toPicos() / oneCycle.toPicos(); assertEquals(expectedReps, targetReps); }
@Test public void testCalculateTargetReps_hugeBenchmark() { long targetReps = calculateTargetReps(INITIAL_REPS, HOURS.toNanos(1), TIMING_INTERVAL.to(NANOSECONDS), 0.0); assertEquals(1, targetReps); }
@Test public void testCalculateTargetReps_applyRandomness() { long targetReps = calculateTargetReps( INITIAL_REPS, MILLISECONDS.toNanos(100), TIMING_INTERVAL.to(NANOSECONDS), 0.5); assertEquals(110, targetReps); }