diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2023-10-10 14:40:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-10 14:40:36 +0100 |
commit | 0606c1140389d8e036087bb24e03bc43d727ffd0 (patch) | |
tree | c1b91f685e8fd9e56d3c54b7d37ccc8609fd4515 | |
parent | 6450334f5bbb059b55005cebfef57fa7969b625e (diff) |
fix(bench): use total time when measuring wavg (#20862)
-rw-r--r-- | cli/js/40_testing.js | 10 | ||||
-rw-r--r-- | cli/tests/testdata/bench/explicit_start_and_end_low_precision.out | 2 | ||||
-rw-r--r-- | cli/tools/bench/reporters.rs | 2 |
3 files changed, 4 insertions, 10 deletions
diff --git a/cli/js/40_testing.js b/cli/js/40_testing.js index 7b60dd133..f4eb0a5a7 100644 --- a/cli/js/40_testing.js +++ b/cli/js/40_testing.js @@ -982,20 +982,17 @@ async function benchMeasure(timeBudget, fn, async, context) { fn(context); const t2 = benchNow(); const totalTime = t2 - t1; - let measuredTime = totalTime; if (currentBenchUserExplicitStart !== null) { - measuredTime -= currentBenchUserExplicitStart - t1; currentBenchUserExplicitStart = null; usedExplicitTimers = true; } if (currentBenchUserExplicitEnd !== null) { - measuredTime -= t2 - currentBenchUserExplicitEnd; currentBenchUserExplicitEnd = null; usedExplicitTimers = true; } c++; - wavg += measuredTime; + wavg += totalTime; budget -= totalTime; } } else { @@ -1004,20 +1001,17 @@ async function benchMeasure(timeBudget, fn, async, context) { await fn(context); const t2 = benchNow(); const totalTime = t2 - t1; - let measuredTime = totalTime; if (currentBenchUserExplicitStart !== null) { - measuredTime -= currentBenchUserExplicitStart - t1; currentBenchUserExplicitStart = null; usedExplicitTimers = true; } if (currentBenchUserExplicitEnd !== null) { - measuredTime -= t2 - currentBenchUserExplicitEnd; currentBenchUserExplicitEnd = null; usedExplicitTimers = true; } c++; - wavg += measuredTime; + wavg += totalTime; budget -= totalTime; } } diff --git a/cli/tests/testdata/bench/explicit_start_and_end_low_precision.out b/cli/tests/testdata/bench/explicit_start_and_end_low_precision.out index e9ac5a864..771164bac 100644 --- a/cli/tests/testdata/bench/explicit_start_and_end_low_precision.out +++ b/cli/tests/testdata/bench/explicit_start_and_end_low_precision.out @@ -6,4 +6,4 @@ benchmark time (avg) iter/s (min … max) ----------------------------------------------------------------------------- ----------------------------- noop with start and end [WILDCARD] [WILDCARD]/iter[WILDCARD]([WILDCARD] … [WILDCARD]) [WILDCARD] 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. +than 10µs per iteration. Remove them for better results. diff --git a/cli/tools/bench/reporters.rs b/cli/tools/bench/reporters.rs index 68788bc96..35b4a229c 100644 --- a/cli/tools/bench/reporters.rs +++ b/cli/tools/bench/reporters.rs @@ -237,7 +237,7 @@ impl BenchReporter for ConsoleReporter { ); if !stats.high_precision && stats.used_explicit_timers { - println!("{}", colors::yellow(format!("Warning: start() and end() calls in \"{}\" are ignored because it averages less\nthan 0.01s per iteration. Remove them for better results.", &desc.name))); + println!("{}", colors::yellow(format!("Warning: start() and end() calls in \"{}\" are ignored because it averages less\nthan 10µs per iteration. Remove them for better results.", &desc.name))); } self.group_measurements.push((desc, stats.clone())); |