       if c.verbose {
         print("    Measuring with scale \(scale).")
       }
-      elapsed_time = sampler.run(test.name, fn: testFn, num_iters: scale)
-    } else {
-      scale = 1
-    }
-    // save result in microseconds
-    samples[s] = elapsed_time / UInt64(scale) / 1000
+      elapsed_time = sampler.measure(test.name, fn: testFn, numIters: scale)
+    }
+
+    samples[s] = elapsed_time
     if c.verbose {
       print("    Sample \(s),\(samples[s])")
     }

      // Compute the scaling factor if a fixed c.fixedNumIters is not specified.
      scale = c.fixedNumIters
      if scale == 1 {
        elapsed_time = sampler.run(test.name, fn: testFn, num_iters: 1)
      }
    }
    // Make integer overflow less likely on platforms where Int is 32 bits wide.

    return timer.diffTimeInNanoSeconds(from: start, to: end)
  }

  /// Measure the `fn` and return the average sample time per iteration (μs).
  func measure(_ name: String, fn: (Int) -> Void, numIters: Int) -> UInt64 {
#if SWIFT_RUNTIME_ENABLE_LEAK_CHECKER
    name.withCString { p in startTrackingObjects(p) }
#endif

    startMeasurement()
    fn(numIters)
    stopMeasurement()

#if SWIFT_RUNTIME_ENABLE_LEAK_CHECKER
    name.withCString { p in stopTrackingObjects(p) }
#endif

    return lastSampleTime / UInt64(numIters) / 1000
  }
}

