Skip to content

Commit e239016

Browse files
committed
catch exceptions in async measure()
1 parent badedd7 commit e239016

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

lib/src/benchmark.dart

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ abstract class SyncBenchmark extends Benchmark {
7979
void setup() {}
8080

8181
/// Clean up after the benchmark has finished.
82-
void teardown() => {};
82+
void teardown() {}
8383

8484
// Measures the [run()] function performance.
8585
@nonVirtual
@@ -124,20 +124,24 @@ abstract class AsyncBenchmark extends Benchmark {
124124
Future<void> setup() async {}
125125

126126
/// Clean up after the benchmark has finished.
127-
Future<void> teardown() async => {};
127+
Future<void> teardown() async {}
128128

129129
// Measures the [run()] function performance.
130130
@nonVirtual
131131
Future<BenchmarkResult> measure([BenchmarkSettings? settings]) async {
132132
settings ??= BenchmarkSettings();
133-
await setup();
134-
// Warmup for at least 100ms. Discard result.
135-
await _measureUntil(settings, run, settings.warmupTime.inMicroseconds);
136-
// Run the benchmark for at least 2000ms.
137-
final result = await _measureUntil(
138-
settings, run, settings.minimumRunTime.inMicroseconds);
139-
await teardown();
140-
return result;
133+
try {
134+
await setup();
135+
// Warmup for at least 100ms. Discard result.
136+
await _measureUntil(settings, run, settings.warmupTime.inMicroseconds);
137+
// Run the benchmark for at least 2000ms.
138+
final result = await _measureUntil(
139+
settings, run, settings.minimumRunTime.inMicroseconds);
140+
await teardown();
141+
return result;
142+
} catch (e) {
143+
return Future.error(e);
144+
}
141145
}
142146

143147
/// Runs [fn] for at least [minimumMicroseconds].

0 commit comments

Comments
 (0)