run method
Start the benchmark. Use log to track down the benchmark progress. If setup, execute or cleanup are futures, they are awaited.
Implementation
Future<BenchmarkResult> run() async {
log.info('Start benchmarking.');
log.fine('Running setup.');
await setup?.call();
if (warmup) {
log.fine('Running 5 warmup test');
for (var i = 0; i < 5; i++) {
await execute();
}
}
final results = <int>[];
log.fine('Executing code $count times.');
var stopwatch = Stopwatch();
for (var i = 0; i < count; i++) {
log.debug('Running test ${i + 1}/${count}');
stopwatch.start();
await execute();
stopwatch.stop();
results.add(stopwatch.elapsedMicroseconds);
stopwatch.reset();
}
log.fine('Running cleanup.');
await cleanup?.call();
log.fine('Benchmark done!');
var r = BenchmarkResult._(results);
log.info(r.prettify());
return r;
}