mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-24 05:25:19 +00:00
chore(cleanup): remove unused legacy benchmarks and scenario files
This commit is contained in:
@@ -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<void> setup() async {
|
|
||||||
di.setupModules([AsyncChainModule()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> teardown() async {
|
|
||||||
di.teardown();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> run() async {
|
|
||||||
await di.resolveAsync<AsyncC>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<Service>(named: serviceName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<Service>(named: serviceName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<Object>(named: 'impl2');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<FooService>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void teardown() => di.teardown();
|
|
||||||
}
|
|
||||||
@@ -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<Shared>();
|
|
||||||
assert(resolved is ChildImpl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import 'package:cherrypick/cherrypick.dart';
|
|
||||||
import 'foo_service.dart';
|
|
||||||
|
|
||||||
class AppModule extends Module {
|
|
||||||
@override
|
|
||||||
void builder(Scope currentScope) {
|
|
||||||
bind<FooService>().toProvide(() => FooService());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<Service>()
|
|
||||||
.toProvide(
|
|
||||||
() => ServiceImpl(
|
|
||||||
value: depName,
|
|
||||||
dependency: currentScope.tryResolve<Service>(
|
|
||||||
named: prevDepName,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.withName(depName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<Service>()
|
|
||||||
.toProvide(
|
|
||||||
() => ServiceImpl(
|
|
||||||
value: depName,
|
|
||||||
dependency: currentScope.tryResolve<Service>(
|
|
||||||
named: prevDepName,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.withName(depName)
|
|
||||||
.singleton();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
import 'shared.dart';
|
|
||||||
class ChildImpl extends Shared {}
|
|
||||||
@@ -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<Shared>().toProvide(() => ChildImpl()).singleton();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
class FooService {}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import 'package:cherrypick/cherrypick.dart';
|
|
||||||
|
|
||||||
class Impl1 {}
|
|
||||||
class Impl2 {}
|
|
||||||
|
|
||||||
class NamedModule extends Module {
|
|
||||||
@override
|
|
||||||
void builder(Scope currentScope) {
|
|
||||||
bind<Object>().toProvide(() => Impl1()).withName('impl1');
|
|
||||||
bind<Object>().toProvide(() => Impl2()).withName('impl2');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
import 'shared.dart';
|
|
||||||
class ParentImpl extends Shared {}
|
|
||||||
@@ -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<Shared>().toProvide(() => ParentImpl()).singleton();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
abstract class Service {
|
|
||||||
final dynamic value;
|
|
||||||
final Service? dependency;
|
|
||||||
Service({required this.value, this.dependency});
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
import 'service.dart';
|
|
||||||
|
|
||||||
class ServiceImpl extends Service {
|
|
||||||
ServiceImpl({required super.value, super.dependency});
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
class Shared {}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import 'package:cherrypick/cherrypick.dart';
|
|
||||||
|
|
||||||
/// Миксин для упрощения работы с CherryPick Scope в бенчмарках.
|
|
||||||
mixin BenchmarkWithScope {
|
|
||||||
Scope? _scope;
|
|
||||||
|
|
||||||
/// Отключить глобальные проверки циклов и создать корневой scope с модулями.
|
|
||||||
void setupScope(List<Module> 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!;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user