diff --git a/benchmark.js b/benchmark.js index f142b3c6..e546c5bb 100644 --- a/benchmark.js +++ b/benchmark.js @@ -1834,6 +1834,7 @@ elapsed = 0, initCount = bench.initCount, minSamples = bench.minSamples, + endAtRME = bench.endAtRME, queue = [], sample = bench.stats.sample; @@ -1935,6 +1936,11 @@ 'variance': variance }); + // Exit early if we have reached a satisfying answer + if (size >= minSamples && rme < endAtRME) { + maxedOut = true; + } + // Abort the cycle loop when the minimum sample size has been collected // and the elapsed time exceeds the maximum time allowed per benchmark. // We don't count cycle delays toward the max time because delays may be @@ -2208,6 +2214,16 @@ */ 'minTime': 0, + /** + * Exit the benchmark early if relative margin of error drops below + * this number. The benchmark will still adhere to the minSamples + * option. + * + * @memberOf Benchmark.options + * @type number + */ + 'endAtRME': 0, + /** * The name of the benchmark. *