diff --git a/benchmark_cherrypick/lib/benchmarks/async_chain_benchmark.dart b/benchmark_cherrypick/lib/benchmarks/async_chain_benchmark.dart deleted file mode 100644 index 68b8ef9..0000000 --- a/benchmark_cherrypick/lib/benchmarks/async_chain_benchmark.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:benchmark_harness/benchmark_harness.dart'; -import 'package:benchmark_cherrypick/di_adapters/di_adapter.dart'; -import 'package:benchmark_cherrypick/scenarios/async_chain_module.dart'; - -class AsyncChainBenchmark extends AsyncBenchmarkBase { - final DIAdapter di; - AsyncChainBenchmark(this.di) : super('AsyncChain (A->B->C, async)'); - - @override - Future setup() async { - di.setupModules([AsyncChainModule()]); - } - - @override - Future teardown() async { - di.teardown(); - } - - @override - Future run() async { - await di.resolveAsync(); - } -} diff --git a/benchmark_cherrypick/lib/benchmarks/chain_factory_benchmark.dart b/benchmark_cherrypick/lib/benchmarks/chain_factory_benchmark.dart deleted file mode 100644 index ddb2b0d..0000000 --- a/benchmark_cherrypick/lib/benchmarks/chain_factory_benchmark.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'package:benchmark_harness/benchmark_harness.dart'; -import 'package:benchmark_cherrypick/di_adapters/di_adapter.dart'; -import 'package:benchmark_cherrypick/scenarios/chain_factory_module.dart'; -import 'package:benchmark_cherrypick/scenarios/service.dart'; - -class ChainFactoryBenchmark extends BenchmarkBase { - final DIAdapter di; - final int chainCount; - final int nestingDepth; - - ChainFactoryBenchmark( - this.di, { - this.chainCount = 1, - this.nestingDepth = 3, - }) : super( - 'ChainFactory (A->B->C, factory). ' - 'C/D = $chainCount/$nestingDepth. ', - ); - - @override - void setup() { - di.setupModules([ - ChainFactoryModule( - chainCount: chainCount, - nestingDepth: nestingDepth, - ), - ]); - } - - @override - void teardown() => di.teardown(); - - @override - void run() { - final serviceName = '${chainCount.toString()}_${nestingDepth.toString()}'; - di.resolve(named: serviceName); - } -} diff --git a/benchmark_cherrypick/lib/benchmarks/chain_singleton_benchmark.dart b/benchmark_cherrypick/lib/benchmarks/chain_singleton_benchmark.dart deleted file mode 100644 index a1ba257..0000000 --- a/benchmark_cherrypick/lib/benchmarks/chain_singleton_benchmark.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'package:benchmark_cherrypick/di_adapters/di_adapter.dart'; -import 'package:benchmark_harness/benchmark_harness.dart'; -import '../scenarios/chain_singleton_module.dart'; -import '../scenarios/service.dart'; - -class ChainSingletonBenchmark extends BenchmarkBase { - final DIAdapter di; - final int chainCount; - final int nestingDepth; - - ChainSingletonBenchmark( - this.di, { - this.chainCount = 1, - this.nestingDepth = 3, - }) : super( - 'ChainSingleton (A->B->C, singleton). ' - 'C/D = $chainCount/$nestingDepth. ', - ); - - @override - void setup() { - di.setupModules([ - ChainSingletonModule( - chainCount: chainCount, - nestingDepth: nestingDepth, - ), - ]); - } - - @override - void teardown() => di.teardown(); - - @override - void run() { - final serviceName = '${chainCount.toString()}_${nestingDepth.toString()}'; - di.resolve(named: serviceName); - } -} diff --git a/benchmark_cherrypick/lib/benchmarks/named_resolve_benchmark.dart b/benchmark_cherrypick/lib/benchmarks/named_resolve_benchmark.dart deleted file mode 100644 index 7a7b8a7..0000000 --- a/benchmark_cherrypick/lib/benchmarks/named_resolve_benchmark.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:benchmark_harness/benchmark_harness.dart'; -import 'package:benchmark_cherrypick/di_adapters/di_adapter.dart'; -import 'package:benchmark_cherrypick/scenarios/named_module.dart'; - -class NamedResolveBenchmark extends BenchmarkBase { - final DIAdapter di; - - NamedResolveBenchmark(this.di) : super('NamedResolve (by name)'); - - @override - void setup() { - di.setupModules([NamedModule()]); - } - - @override - void teardown() => di.teardown(); - - @override - void run() { - di.resolve(named: 'impl2'); - } -} diff --git a/benchmark_cherrypick/lib/benchmarks/register_and_resolve_benchmark.dart b/benchmark_cherrypick/lib/benchmarks/register_and_resolve_benchmark.dart deleted file mode 100644 index a2442fe..0000000 --- a/benchmark_cherrypick/lib/benchmarks/register_and_resolve_benchmark.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:benchmark_harness/benchmark_harness.dart'; -import 'package:benchmark_cherrypick/di_adapters/di_adapter.dart'; -import 'package:benchmark_cherrypick/scenarios/app_module.dart'; -import 'package:benchmark_cherrypick/scenarios/foo_service.dart'; - -class RegisterAndResolveBenchmark extends BenchmarkBase { - final DIAdapter di; - - RegisterAndResolveBenchmark(this.di) : super('RegisterAndResolve'); - - @override - void setup() { - di.setupModules([AppModule()]); - } - - @override - void run() { - di.resolve(); - } - - @override - void teardown() => di.teardown(); -} diff --git a/benchmark_cherrypick/lib/benchmarks/scope_override_benchmark.dart b/benchmark_cherrypick/lib/benchmarks/scope_override_benchmark.dart deleted file mode 100644 index 4c96a3b..0000000 --- a/benchmark_cherrypick/lib/benchmarks/scope_override_benchmark.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:benchmark_harness/benchmark_harness.dart'; -import 'package:benchmark_cherrypick/di_adapters/di_adapter.dart'; -import 'package:benchmark_cherrypick/scenarios/parent_module.dart'; -import 'package:benchmark_cherrypick/scenarios/child_override_module.dart'; -import 'package:benchmark_cherrypick/scenarios/shared.dart'; -import 'package:benchmark_cherrypick/scenarios/child_impl.dart'; - -class ScopeOverrideBenchmark extends BenchmarkBase { - final DIAdapter di; - late DIAdapter childDi; - - ScopeOverrideBenchmark(this.di) : super('ScopeOverride (child overrides parent)'); - - @override - void setup() { - di.setupModules([ParentModule()]); - childDi = di.openSubScope('child'); - childDi.setupModules([ChildOverrideModule()]); - } - - @override - void teardown() => di.teardown(); - - @override - void run() { - final resolved = childDi.resolve(); - assert(resolved is ChildImpl); - } -} diff --git a/benchmark_cherrypick/lib/scenarios/app_module.dart b/benchmark_cherrypick/lib/scenarios/app_module.dart deleted file mode 100644 index fa68fd9..0000000 --- a/benchmark_cherrypick/lib/scenarios/app_module.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:cherrypick/cherrypick.dart'; -import 'foo_service.dart'; - -class AppModule extends Module { - @override - void builder(Scope currentScope) { - bind().toProvide(() => FooService()); - } -} diff --git a/benchmark_cherrypick/lib/scenarios/async_chain_module.dart b/benchmark_cherrypick/lib/scenarios/async_chain_module.dart deleted file mode 100644 index e0044e9..0000000 --- a/benchmark_cherrypick/lib/scenarios/async_chain_module.dart +++ /dev/null @@ -1,20 +0,0 @@ -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().toProvideAsync(() async => AsyncA()).singleton(); - bind().toProvideAsync(() async => AsyncB(await currentScope.resolveAsync())).singleton(); - bind().toProvideAsync(() async => AsyncC(await currentScope.resolveAsync())).singleton(); - } -} diff --git a/benchmark_cherrypick/lib/scenarios/chain_factory_module.dart b/benchmark_cherrypick/lib/scenarios/chain_factory_module.dart deleted file mode 100644 index ade4ccf..0000000 --- a/benchmark_cherrypick/lib/scenarios/chain_factory_module.dart +++ /dev/null @@ -1,42 +0,0 @@ -// === DI graph: A -> B -> C (factory/no singleton) === -import 'package:cherrypick/cherrypick.dart'; - -import 'service.dart'; -import 'service_impl.dart'; - -class ChainFactoryModule extends Module { - // количество независимых цепочек - final int chainCount; - - // глубина вложенности - final int nestingDepth; - - ChainFactoryModule({ - required this.chainCount, - required this.nestingDepth, - }); - - @override - void builder(Scope currentScope) { - for (var chainIndex = 0; chainIndex < chainCount; chainIndex++) { - for (var levelIndex = 0; levelIndex < nestingDepth; levelIndex++) { - final chain = chainIndex + 1; - final level = levelIndex + 1; - - final prevDepName = '${chain.toString()}_${(level - 1).toString()}'; - final depName = '${chain.toString()}_${level.toString()}'; - - bind() - .toProvide( - () => ServiceImpl( - value: depName, - dependency: currentScope.tryResolve( - named: prevDepName, - ), - ), - ) - .withName(depName); - } - } - } -} \ No newline at end of file diff --git a/benchmark_cherrypick/lib/scenarios/chain_singleton_module.dart b/benchmark_cherrypick/lib/scenarios/chain_singleton_module.dart deleted file mode 100644 index 72fa5ca..0000000 --- a/benchmark_cherrypick/lib/scenarios/chain_singleton_module.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'package:cherrypick/cherrypick.dart'; - -import 'service.dart'; -import 'service_impl.dart'; - -class ChainSingletonModule extends Module { - // количество независимых цепочек - final int chainCount; - - // глубина вложенности - final int nestingDepth; - - ChainSingletonModule({ - required this.chainCount, - required this.nestingDepth, - }); - - @override - void builder(Scope currentScope) { - for (var chainIndex = 0; chainIndex < chainCount; chainIndex++) { - for (var levelIndex = 0; levelIndex < nestingDepth; levelIndex++) { - final chain = chainIndex + 1; - final level = levelIndex + 1; - - final prevDepName = '${chain.toString()}_${(level - 1).toString()}'; - final depName = '${chain.toString()}_${level.toString()}'; - - bind() - .toProvide( - () => ServiceImpl( - value: depName, - dependency: currentScope.tryResolve( - named: prevDepName, - ), - ), - ) - .withName(depName) - .singleton(); - } - } - } -} diff --git a/benchmark_cherrypick/lib/scenarios/child_impl.dart b/benchmark_cherrypick/lib/scenarios/child_impl.dart deleted file mode 100644 index e564b60..0000000 --- a/benchmark_cherrypick/lib/scenarios/child_impl.dart +++ /dev/null @@ -1,2 +0,0 @@ -import 'shared.dart'; -class ChildImpl extends Shared {} diff --git a/benchmark_cherrypick/lib/scenarios/child_override_module.dart b/benchmark_cherrypick/lib/scenarios/child_override_module.dart deleted file mode 100644 index 3ace258..0000000 --- a/benchmark_cherrypick/lib/scenarios/child_override_module.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'package:cherrypick/cherrypick.dart'; -import 'child_impl.dart'; -import 'shared.dart'; - -class ChildOverrideModule extends Module { - @override - void builder(Scope currentScope) { - bind().toProvide(() => ChildImpl()).singleton(); - } -} diff --git a/benchmark_cherrypick/lib/scenarios/foo_service.dart b/benchmark_cherrypick/lib/scenarios/foo_service.dart deleted file mode 100644 index d72c805..0000000 --- a/benchmark_cherrypick/lib/scenarios/foo_service.dart +++ /dev/null @@ -1 +0,0 @@ -class FooService {} diff --git a/benchmark_cherrypick/lib/scenarios/named_module.dart b/benchmark_cherrypick/lib/scenarios/named_module.dart deleted file mode 100644 index a0708c0..0000000 --- a/benchmark_cherrypick/lib/scenarios/named_module.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:cherrypick/cherrypick.dart'; - -class Impl1 {} -class Impl2 {} - -class NamedModule extends Module { - @override - void builder(Scope currentScope) { - bind().toProvide(() => Impl1()).withName('impl1'); - bind().toProvide(() => Impl2()).withName('impl2'); - } -} diff --git a/benchmark_cherrypick/lib/scenarios/parent_impl.dart b/benchmark_cherrypick/lib/scenarios/parent_impl.dart deleted file mode 100644 index e6a5f40..0000000 --- a/benchmark_cherrypick/lib/scenarios/parent_impl.dart +++ /dev/null @@ -1,2 +0,0 @@ -import 'shared.dart'; -class ParentImpl extends Shared {} diff --git a/benchmark_cherrypick/lib/scenarios/parent_module.dart b/benchmark_cherrypick/lib/scenarios/parent_module.dart deleted file mode 100644 index 2e3d83f..0000000 --- a/benchmark_cherrypick/lib/scenarios/parent_module.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'package:cherrypick/cherrypick.dart'; -import 'parent_impl.dart'; -import 'shared.dart'; - -class ParentModule extends Module { - @override - void builder(Scope currentScope) { - bind().toProvide(() => ParentImpl()).singleton(); - } -} diff --git a/benchmark_cherrypick/lib/scenarios/service.dart b/benchmark_cherrypick/lib/scenarios/service.dart deleted file mode 100644 index 065646b..0000000 --- a/benchmark_cherrypick/lib/scenarios/service.dart +++ /dev/null @@ -1,5 +0,0 @@ -abstract class Service { - final dynamic value; - final Service? dependency; - Service({required this.value, this.dependency}); -} diff --git a/benchmark_cherrypick/lib/scenarios/service_impl.dart b/benchmark_cherrypick/lib/scenarios/service_impl.dart deleted file mode 100644 index 58ee09b..0000000 --- a/benchmark_cherrypick/lib/scenarios/service_impl.dart +++ /dev/null @@ -1,5 +0,0 @@ -import 'service.dart'; - -class ServiceImpl extends Service { - ServiceImpl({required super.value, super.dependency}); -} diff --git a/benchmark_cherrypick/lib/scenarios/shared.dart b/benchmark_cherrypick/lib/scenarios/shared.dart deleted file mode 100644 index f3aa38b..0000000 --- a/benchmark_cherrypick/lib/scenarios/shared.dart +++ /dev/null @@ -1 +0,0 @@ -class Shared {} diff --git a/benchmark_cherrypick/lib/utils/benchmark_utils.dart b/benchmark_cherrypick/lib/utils/benchmark_utils.dart deleted file mode 100644 index 4d1a302..0000000 --- a/benchmark_cherrypick/lib/utils/benchmark_utils.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:cherrypick/cherrypick.dart'; - -/// Миксин для упрощения работы с CherryPick Scope в бенчмарках. -mixin BenchmarkWithScope { - Scope? _scope; - - /// Отключить глобальные проверки циклов и создать корневой scope с модулями. - void setupScope(List modules, - {bool disableCycleDetection = true, - bool disableCrossScopeCycleDetection = true}) { - if (disableCycleDetection) { - CherryPick.disableGlobalCycleDetection(); - } - if (disableCrossScopeCycleDetection) { - CherryPick.disableGlobalCrossScopeCycleDetection(); - } - _scope = CherryPick.openRootScope(); - _scope!.installModules(modules); - } - - /// Закрывает текущий scope. - void teardownScope() { - CherryPick.closeRootScope(); - _scope = null; - } - - /// Получить текущий scope. Не null после setupScope. - Scope get scope => _scope!; -}