mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-23 21:13:35 +00:00
Add complex DI benchmarks, main runner, and English README with summarized results for cherrypick core
This commit is contained in:
40
benchmark_cherrypick/lib/async_chain_benchmark.dart
Normal file
40
benchmark_cherrypick/lib/async_chain_benchmark.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:benchmark_harness/benchmark_harness.dart';
|
||||
import 'package:cherrypick/cherrypick.dart';
|
||||
|
||||
class AsyncA {}
|
||||
class AsyncB {
|
||||
final AsyncA a;
|
||||
AsyncB(this.a);
|
||||
}
|
||||
class AsyncC {
|
||||
final AsyncB b;
|
||||
AsyncC(this.b);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncChainBenchmark extends AsyncBenchmarkBase {
|
||||
AsyncChainBenchmark() : super('AsyncChain (A->B->C, async)');
|
||||
late Scope scope;
|
||||
|
||||
@override
|
||||
Future<void> setup() async {
|
||||
scope = CherryPick.openRootScope();
|
||||
scope.installModules([AsyncChainModule()]);
|
||||
}
|
||||
@override
|
||||
Future<void> teardown() async {
|
||||
CherryPick.closeRootScope();
|
||||
}
|
||||
@override
|
||||
Future<void> run() async {
|
||||
await scope.resolveAsync<AsyncC>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user