Skip to content

Commit 2048ac6

Browse files
Benchmark: print how often benchmark was re-run to reach min run time.
1 parent 67b4ded commit 2048ac6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

benchmark/lib/benchmark.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Benchmark {
6666
}
6767

6868
/// Runs [f] for at least [minimumMillis] milliseconds.
69-
static Future<double> _measureFor(Function f, int minimumMillis) async {
69+
Future<double> _measureFor(Function f, int minimumMillis, bool warmUp) async {
7070
final minimumMicros = minimumMillis * 1000;
7171
var iter = 0;
7272
final watch = Stopwatch()..start();
@@ -76,6 +76,12 @@ class Benchmark {
7676
elapsed = watch.elapsedMicroseconds;
7777
iter++;
7878
}
79+
if (!warmUp) {
80+
// Print how often f had to be re-run to reach minimum run time.
81+
final reruns = iter - 1;
82+
print('$name(re-runs): '
83+
'${Emitter._format(reruns.toDouble(), decimalPoints: 0)}');
84+
}
7985
return elapsed / iter;
8086
}
8187

@@ -86,9 +92,9 @@ class Benchmark {
8692
Future<double> _measure() async {
8793
setup();
8894
// Warmup for at least 100ms. Discard result.
89-
await _measureFor(run, 100);
95+
await _measureFor(run, 100, true);
9096
// Run the benchmark for at least 2000ms.
91-
var result = await _measureFor(run, 2000);
97+
var result = await _measureFor(run, 2000, false);
9298
teardown();
9399
return result;
94100
}

0 commit comments

Comments
 (0)