refactor(benchmarks): unify benchmark structure, enable CLI parameterization, run matrix, add CSV/JSON/pretty output

- All benchmarks now use a unified base mixin for setup/teardown (BenchmarkWithScope).
- Added args package support: CLI flags for choosing benchmarks, chain counts, nesting depths, output format.
- Support for running benchmarks in matrix mode (multiple parameter sets).
- Machine-readable output: csv, json, pretty-table.
- Loop and naming lint fixes, unused imports removed.
This commit is contained in:
Sergey Penkovsky
2025-08-06 13:29:23 +03:00
parent a5ef0dc437
commit 926bbf15f4
8 changed files with 211 additions and 71 deletions

View File

@@ -1,12 +1,15 @@
// ignore: depend_on_referenced_packages
import 'package:benchmark_harness/benchmark_harness.dart';
import 'package:cherrypick/cherrypick.dart';
import 'benchmark_utils.dart';
class AsyncA {}
class AsyncB {
final AsyncA a;
AsyncB(this.a);
}
class AsyncC {
final AsyncB b;
AsyncC(this.b);
@@ -16,26 +19,30 @@ class AsyncChainModule extends Module {
@override
void builder(Scope currentScope) {
bind<AsyncA>().toProvideAsync(() async => AsyncA()).singleton();
bind<AsyncB>().toProvideAsync(() async => AsyncB(await currentScope.resolveAsync<AsyncA>())).singleton();
bind<AsyncC>().toProvideAsync(() async => AsyncC(await currentScope.resolveAsync<AsyncB>())).singleton();
bind<AsyncB>()
.toProvideAsync(
() async => AsyncB(await currentScope.resolveAsync<AsyncA>()))
.singleton();
bind<AsyncC>()
.toProvideAsync(
() async => AsyncC(await currentScope.resolveAsync<AsyncB>()))
.singleton();
}
}
class AsyncChainBenchmark extends AsyncBenchmarkBase {
class AsyncChainBenchmark extends AsyncBenchmarkBase with BenchmarkWithScope {
AsyncChainBenchmark() : super('AsyncChain (A->B->C, async)');
late Scope scope;
@override
Future<void> setup() async {
CherryPick.disableGlobalCycleDetection();
CherryPick.disableGlobalCrossScopeCycleDetection();
scope = CherryPick.openRootScope();
scope.installModules([AsyncChainModule()]);
setupScope([AsyncChainModule()]);
}
@override
Future<void> teardown() async {
CherryPick.closeRootScope();
teardownScope();
}
@override
Future<void> run() async {
await scope.resolveAsync<AsyncC>();