summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2023-08-26 10:29:45 +0100
committerGitHub <noreply@github.com>2023-08-26 11:29:45 +0200
commit5dbf5c82936a1975067101e25580790c8b7c50b7 (patch)
treed0d869ef0bd801d2bbefe3fee577d2068ff1a9a2 /cli/js
parent1cb547d885906d557a63b2670c4b1b95a8626826 (diff)
fix(bench): explicit timers don't force high precision measurements (#20272)
Disables `BenchContext::start()` and `BenchContext::end()` for low precision benchmarks (less than 0.01s per iteration). Prints a warning when they are used in such benchmarks, suggesting to remove them. ```ts Deno.bench("noop", { group: "noops" }, () => {}); Deno.bench("noop with start/end", { group: "noops" }, (b) => { b.start(); b.end(); }); ``` Before: ``` cpu: 12th Gen Intel(R) Core(TM) i9-12900K runtime: deno 1.36.2 (x86_64-unknown-linux-gnu) file:///home/nayeem/projects/deno/temp3.ts benchmark time (avg) iter/s (min … max) p75 p99 p995 ----------------------------------------------------------------------------- ----------------------------- noop 2.63 ns/iter 380,674,131.4 (2.45 ns … 27.78 ns) 2.55 ns 4.03 ns 5.33 ns noop with start and end 302.47 ns/iter 3,306,146.0 (200 ns … 151.2 µs) 300 ns 400 ns 400 ns summary noop 115.14x faster than noop with start and end ``` After: ``` cpu: 12th Gen Intel(R) Core(TM) i9-12900K runtime: deno 1.36.1 (x86_64-unknown-linux-gnu) file:///home/nayeem/projects/deno/temp3.ts benchmark time (avg) iter/s (min … max) p75 p99 p995 ----------------------------------------------------------------------------- ----------------------------- noop 3.01 ns/iter 332,565,561.7 (2.73 ns … 29.54 ns) 2.93 ns 5.29 ns 7.45 ns noop with start and end 7.73 ns/iter 129,291,091.5 (6.61 ns … 46.76 ns) 7.87 ns 13.12 ns 15.32 ns Warning start() and end() calls in "noop with start and end" are ignored because it averages less than 0.01s per iteration. Remove them for better results. summary noop 2.57x faster than noop with start and end ```
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/40_testing.js20
1 files changed, 15 insertions, 5 deletions
diff --git a/cli/js/40_testing.js b/cli/js/40_testing.js
index 21417db23..afa9a6552 100644
--- a/cli/js/40_testing.js
+++ b/cli/js/40_testing.js
@@ -849,7 +849,7 @@ function compareMeasurements(a, b) {
return 0;
}
-function benchStats(n, highPrecision, avg, min, max, all) {
+function benchStats(n, highPrecision, usedExplicitTimers, avg, min, max, all) {
return {
n,
min,
@@ -859,6 +859,8 @@ function benchStats(n, highPrecision, avg, min, max, all) {
p995: all[MathCeil(n * (99.5 / 100)) - 1],
p999: all[MathCeil(n * (99.9 / 100)) - 1],
avg: !highPrecision ? (avg / n) : MathCeil(avg / n),
+ highPrecision,
+ usedExplicitTimers,
};
}
@@ -926,7 +928,7 @@ async function benchMeasure(timeBudget, fn, async, context) {
wavg /= c;
// measure step
- if (wavg > lowPrecisionThresholdInNs || usedExplicitTimers) {
+ if (wavg > lowPrecisionThresholdInNs) {
let iterations = 10;
let budget = timeBudget * 1e6;
@@ -978,6 +980,8 @@ async function benchMeasure(timeBudget, fn, async, context) {
}
}
} else {
+ context.start = function start() {};
+ context.end = function end() {};
let iterations = 10;
let budget = timeBudget * 1e6;
@@ -986,8 +990,6 @@ async function benchMeasure(timeBudget, fn, async, context) {
const t1 = benchNow();
for (let c = 0; c < lowPrecisionThresholdInNs; c++) {
fn(context);
- currentBenchUserExplicitStart = null;
- currentBenchUserExplicitEnd = null;
}
const iterationTime = (benchNow() - t1) / lowPrecisionThresholdInNs;
@@ -1019,7 +1021,15 @@ async function benchMeasure(timeBudget, fn, async, context) {
}
all.sort(compareMeasurements);
- return benchStats(n, wavg > lowPrecisionThresholdInNs, avg, min, max, all);
+ return benchStats(
+ n,
+ wavg > lowPrecisionThresholdInNs,
+ usedExplicitTimers,
+ avg,
+ min,
+ max,
+ all,
+ );
}
/** @param desc {BenchDescription} */