diff --git a/benchmark_cherrypick/analysis_options.yaml b/benchmark_cherrypick/analysis_options.yaml index 95b8ade..6bd1e89 100644 --- a/benchmark_cherrypick/analysis_options.yaml +++ b/benchmark_cherrypick/analysis_options.yaml @@ -15,6 +15,7 @@ include: package:lints/recommended.yaml analyzer: errors: deprecated_member_use: ignore + depend_on_referenced_packages: ignore # Uncomment the following section to specify additional rules. diff --git a/benchmark_cherrypick/bin/main.dart b/benchmark_cherrypick/bin/main.dart index 12c5185..2112cf4 100644 --- a/benchmark_cherrypick/bin/main.dart +++ b/benchmark_cherrypick/bin/main.dart @@ -1,8 +1,10 @@ -import 'package:benchmark_cherrypick/cherrypick_benchmark.dart'; -import 'package:benchmark_cherrypick/complex_bindings_benchmark.dart'; -import 'package:benchmark_cherrypick/async_chain_benchmark.dart'; -import 'package:benchmark_cherrypick/di_adapter.dart'; -import 'package:benchmark_cherrypick/scope_override_benchmark.dart'; +import 'package:benchmark_cherrypick/benchmarks/register_and_resolve_benchmark.dart'; +import 'package:benchmark_cherrypick/benchmarks/chain_singleton_benchmark.dart'; +import 'package:benchmark_cherrypick/benchmarks/chain_factory_benchmark.dart'; +import 'package:benchmark_cherrypick/benchmarks/named_resolve_benchmark.dart'; +import 'package:benchmark_cherrypick/benchmarks/scope_override_benchmark.dart'; +import 'package:benchmark_cherrypick/benchmarks/async_chain_benchmark.dart'; +import 'package:benchmark_cherrypick/di_adapters/cherrypick_adapter.dart'; import 'package:args/args.dart'; import 'dart:io'; import 'dart:math'; diff --git a/benchmark_cherrypick/lib/async_chain_benchmark.dart b/benchmark_cherrypick/lib/async_chain_benchmark.dart deleted file mode 100644 index 636f8ba..0000000 --- a/benchmark_cherrypick/lib/async_chain_benchmark.dart +++ /dev/null @@ -1,52 +0,0 @@ -// ignore: depend_on_referenced_packages -import 'package:benchmark_cherrypick/di_adapter.dart'; -// ignore: depend_on_referenced_packages -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().toProvideAsync(() async => AsyncA()).singleton(); - bind() - .toProvideAsync( - () async => AsyncB(await currentScope.resolveAsync())) - .singleton(); - bind() - .toProvideAsync( - () async => AsyncC(await currentScope.resolveAsync())) - .singleton(); - } -} - -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/async_chain_benchmark.dart b/benchmark_cherrypick/lib/benchmarks/async_chain_benchmark.dart new file mode 100644 index 0000000..68b8ef9 --- /dev/null +++ b/benchmark_cherrypick/lib/benchmarks/async_chain_benchmark.dart @@ -0,0 +1,23 @@ +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 new file mode 100644 index 0000000..ddb2b0d --- /dev/null +++ b/benchmark_cherrypick/lib/benchmarks/chain_factory_benchmark.dart @@ -0,0 +1,38 @@ +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 new file mode 100644 index 0000000..a1ba257 --- /dev/null +++ b/benchmark_cherrypick/lib/benchmarks/chain_singleton_benchmark.dart @@ -0,0 +1,38 @@ +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 new file mode 100644 index 0000000..7a7b8a7 --- /dev/null +++ b/benchmark_cherrypick/lib/benchmarks/named_resolve_benchmark.dart @@ -0,0 +1,22 @@ +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/cherrypick_benchmark.dart b/benchmark_cherrypick/lib/benchmarks/register_and_resolve_benchmark.dart similarity index 51% rename from benchmark_cherrypick/lib/cherrypick_benchmark.dart rename to benchmark_cherrypick/lib/benchmarks/register_and_resolve_benchmark.dart index caeb56d..a2442fe 100644 --- a/benchmark_cherrypick/lib/cherrypick_benchmark.dart +++ b/benchmark_cherrypick/lib/benchmarks/register_and_resolve_benchmark.dart @@ -1,18 +1,7 @@ -// ignore: depend_on_referenced_packages -import 'package:benchmark_cherrypick/di_adapter.dart'; -// ignore: depend_on_referenced_packages import 'package:benchmark_harness/benchmark_harness.dart'; -import 'package:cherrypick/cherrypick.dart'; - -class AppModule extends Module { - @override - void builder(Scope currentScope) { - bind().toProvide(() => FooService()); - } -} - -// Dummy service for DI -class FooService {} +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; diff --git a/benchmark_cherrypick/lib/benchmarks/scope_override_benchmark.dart b/benchmark_cherrypick/lib/benchmarks/scope_override_benchmark.dart new file mode 100644 index 0000000..4c96a3b --- /dev/null +++ b/benchmark_cherrypick/lib/benchmarks/scope_override_benchmark.dart @@ -0,0 +1,29 @@ +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/complex_bindings_benchmark.dart b/benchmark_cherrypick/lib/complex_bindings_benchmark.dart deleted file mode 100644 index 51a4f3f..0000000 --- a/benchmark_cherrypick/lib/complex_bindings_benchmark.dart +++ /dev/null @@ -1,199 +0,0 @@ -// ignore: depend_on_referenced_packages -import 'package:benchmark_cherrypick/di_adapter.dart'; -// ignore: depend_on_referenced_packages -import 'package:benchmark_harness/benchmark_harness.dart'; -import 'package:cherrypick/cherrypick.dart'; - -// === DI graph: A -> B -> C (singleton) === -abstract class Service { - final dynamic value; - final Service? dependency; - - Service({ - required this.value, - this.dependency, - }); -} - -class ServiceImpl extends Service { - ServiceImpl({ - required super.value, - super.dependency, - }); -} - -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(); - } - } - } -} - -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); - } -} - -// === DI graph: A -> B -> C (factory/no singleton) === -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); - } - } - } -} - -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); - } -} - -// === Named bindings: Multiple implementations === -class Impl1 {} - -class Impl2 {} - -class NamedModule extends Module { - @override - void builder(Scope currentScope) { - bind().toProvide(() => Impl1()).withName('impl1'); - bind().toProvide(() => Impl2()).withName('impl2'); - } -} - -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/di_adapter.dart b/benchmark_cherrypick/lib/di_adapters/cherrypick_adapter.dart similarity index 88% rename from benchmark_cherrypick/lib/di_adapter.dart rename to benchmark_cherrypick/lib/di_adapters/cherrypick_adapter.dart index aed5ecc..e9489ec 100644 --- a/benchmark_cherrypick/lib/di_adapter.dart +++ b/benchmark_cherrypick/lib/di_adapters/cherrypick_adapter.dart @@ -1,12 +1,5 @@ import 'package:cherrypick/cherrypick.dart'; - -abstract class DIAdapter { - void setupModules(List modules); - T resolve({String? named}); - Future resolveAsync({String? named}); - void teardown(); - DIAdapter openSubScope(String name); -} +import 'di_adapter.dart'; class CherrypickDIAdapter implements DIAdapter { Scope? _scope; diff --git a/benchmark_cherrypick/lib/di_adapters/di_adapter.dart b/benchmark_cherrypick/lib/di_adapters/di_adapter.dart new file mode 100644 index 0000000..de818e3 --- /dev/null +++ b/benchmark_cherrypick/lib/di_adapters/di_adapter.dart @@ -0,0 +1,9 @@ +import 'package:cherrypick/cherrypick.dart'; + +abstract class DIAdapter { + void setupModules(List modules); + T resolve({String? named}); + Future resolveAsync({String? named}); + void teardown(); + DIAdapter openSubScope(String name); +} diff --git a/benchmark_cherrypick/lib/scenarios/app_module.dart b/benchmark_cherrypick/lib/scenarios/app_module.dart new file mode 100644 index 0000000..fa68fd9 --- /dev/null +++ b/benchmark_cherrypick/lib/scenarios/app_module.dart @@ -0,0 +1,9 @@ +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 new file mode 100644 index 0000000..e0044e9 --- /dev/null +++ b/benchmark_cherrypick/lib/scenarios/async_chain_module.dart @@ -0,0 +1,20 @@ +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 new file mode 100644 index 0000000..ade4ccf --- /dev/null +++ b/benchmark_cherrypick/lib/scenarios/chain_factory_module.dart @@ -0,0 +1,42 @@ +// === 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 new file mode 100644 index 0000000..72fa5ca --- /dev/null +++ b/benchmark_cherrypick/lib/scenarios/chain_singleton_module.dart @@ -0,0 +1,42 @@ +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 new file mode 100644 index 0000000..e564b60 --- /dev/null +++ b/benchmark_cherrypick/lib/scenarios/child_impl.dart @@ -0,0 +1,2 @@ +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 new file mode 100644 index 0000000..3ace258 --- /dev/null +++ b/benchmark_cherrypick/lib/scenarios/child_override_module.dart @@ -0,0 +1,10 @@ +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 new file mode 100644 index 0000000..d72c805 --- /dev/null +++ b/benchmark_cherrypick/lib/scenarios/foo_service.dart @@ -0,0 +1 @@ +class FooService {} diff --git a/benchmark_cherrypick/lib/scenarios/named_module.dart b/benchmark_cherrypick/lib/scenarios/named_module.dart new file mode 100644 index 0000000..a0708c0 --- /dev/null +++ b/benchmark_cherrypick/lib/scenarios/named_module.dart @@ -0,0 +1,12 @@ +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 new file mode 100644 index 0000000..e6a5f40 --- /dev/null +++ b/benchmark_cherrypick/lib/scenarios/parent_impl.dart @@ -0,0 +1,2 @@ +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 new file mode 100644 index 0000000..2e3d83f --- /dev/null +++ b/benchmark_cherrypick/lib/scenarios/parent_module.dart @@ -0,0 +1,10 @@ +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 new file mode 100644 index 0000000..065646b --- /dev/null +++ b/benchmark_cherrypick/lib/scenarios/service.dart @@ -0,0 +1,5 @@ +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 new file mode 100644 index 0000000..58ee09b --- /dev/null +++ b/benchmark_cherrypick/lib/scenarios/service_impl.dart @@ -0,0 +1,5 @@ +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 new file mode 100644 index 0000000..f3aa38b --- /dev/null +++ b/benchmark_cherrypick/lib/scenarios/shared.dart @@ -0,0 +1 @@ +class Shared {} diff --git a/benchmark_cherrypick/lib/scope_override_benchmark.dart b/benchmark_cherrypick/lib/scope_override_benchmark.dart deleted file mode 100644 index e976c1d..0000000 --- a/benchmark_cherrypick/lib/scope_override_benchmark.dart +++ /dev/null @@ -1,49 +0,0 @@ -// ignore: depend_on_referenced_packages -import 'package:benchmark_cherrypick/di_adapter.dart'; -// ignore: depend_on_referenced_packages -import 'package:benchmark_harness/benchmark_harness.dart'; -import 'package:cherrypick/cherrypick.dart'; - -class Shared {} - -class ParentImpl extends Shared {} - -class ChildImpl extends Shared {} - -class ParentModule extends Module { - @override - void builder(Scope currentScope) { - bind().toProvide(() => ParentImpl()).singleton(); - } -} - -class ChildOverrideModule extends Module { - @override - void builder(Scope currentScope) { - bind().toProvide(() => ChildImpl()).singleton(); - } -} - -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() { - // Should return ChildImpl, not ParentImpl - final resolved = childDi.resolve(); - assert(resolved is ChildImpl); - } -} diff --git a/benchmark_cherrypick/lib/benchmark_utils.dart b/benchmark_cherrypick/lib/utils/benchmark_utils.dart similarity index 100% rename from benchmark_cherrypick/lib/benchmark_utils.dart rename to benchmark_cherrypick/lib/utils/benchmark_utils.dart