   test.setUpFunction?()
 
   for s in 0..<c.numSamples {
-    let nsPerSecond = 1_000_000_000.0 // nanoseconds
-    let time_per_sample = UInt64(c.sampleTime * nsPerSecond)
-
     var scale : Int
     var elapsed_time : UInt64 = 0
     if c.fixedNumIters == 0 {
-      elapsed_time = sampler.run(test.name, fn: testFn, num_iters: 1)
+      elapsed_time = sampler.measure(test.name, fn: testFn, numIters: 1)
 
       if elapsed_time > 0 {
-        scale = Int(time_per_sample / elapsed_time)
+        let usPerSecond = 1_000_000.0 // microseconds (μs)
+        let timePerSample = UInt64(c.sampleTime * usPerSecond)
+        /// Number of iterations to make `testFn` run for the desired time.
+        scale = Int(timePerSample / elapsed_time)
       } else {
         if c.verbose {
           print("    Warning: elapsed time is 0. This can be safely ignored if the body is empty.")

      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
    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.measure(test.name, fn: testFn, numIters: 1)
      }
    }
    // Make integer overflow less likely on platforms where Int is 32 bits wide.
