run method
Future<BenchmarkResult>
run({
- required String name,
- required VmBenchmarkOperation operation,
- BenchmarkCancellationToken? cancellation,
- Map<
String, Object?> metadata = const {},
Runs operation and returns timing statistics for completed samples.
Cancellation stops before adding the cancelled sample; metadata is
copied into the resulting report for test diagnostics.
Implementation
Future<BenchmarkResult> run({
required String name,
required VmBenchmarkOperation operation,
BenchmarkCancellationToken? cancellation,
Map<String, Object?> metadata = const {},
}) async {
final token = cancellation ?? BenchmarkCancellationToken();
var completedWarmups = 0;
for (var index = 0; index < warmupCount; index++) {
if (token.isCancelled) break;
final completed = await _runOne(index, operation, token);
if (completed == null) break;
completedWarmups++;
}
final samples = <BenchmarkSample>[];
for (var index = 0; index < repetitionCount; index++) {
if (token.isCancelled) break;
final completed = await _runOne(index, operation, token);
if (completed == null) break;
samples.add(completed);
}
return BenchmarkResult(
name: name,
cancelled: token.isCancelled,
metadata: metadata,
statistics: BenchmarkStatistics(
warmupCount: completedWarmups,
samples: samples,
),
);
}