sclass BenchForNSeconds { Runnable action; double duration; // how many seconds to run the benchmark volatile bool done; long iterations; O lastResult; long start, endTime; gettable new AverageAndMinMax stats; run { start = sysNanos(); endTime = start+secondsToNanos(duration); long time = sysNanos(); while (time < endTime) { action?.run(); ++iterations; long time2 = sysNanos(); long runTook = time2-time; stats.add(runTook); time = time2; } endTime = time; set done; } }