docs(benchmarks): update README files with new CLI, matrix run, output formats, and usage instructions (EN+RU)

This commit is contained in:
Sergey Penkovsky
2025-08-06 13:35:39 +03:00
parent 926bbf15f4
commit 7f488f873e
2 changed files with 155 additions and 41 deletions

View File

@@ -1,28 +1,29 @@
# benchmark_cherrypick
Benchmarks for performance and features of the cherrypick (core) DI container.
Benchmarks for the performance and features of the cherrypick (core) DI container.
All scenarios use the public API capabilities of cherrypick (scope, module, binding, scoping, and async support).
All scenarios use only the public API (scope, module, binding, scoping, and async).
## Scenarios
- **RegisterAndResolve**: basic registration and resolution of a dependency.
- **ChainSingleton (A->B->C, singleton)**: dependency chain, all as singletons.
- **ChainFactory (A->B->C, factory)**: dependency chain with factory bindings (new instance on each request).
- **NamedResolve (by name)**: resolving a named dependency among multiple implementations.
- **AsyncChain (A->B->C, async)**: asynchronous dependency chain.
- **ScopeOverride (child overrides parent)**: overriding a dependency in a child scope over a parent.
- **RegisterAndResolve**: Basic registration and resolution of a dependency.
- **ChainSingleton (A->B->C, singleton)**: Deep dependency chain, all as singletons.
- **ChainFactory (A->B->C, factory)**: Dependency chain with factory bindings (new instance per request).
- **NamedResolve (by name)**: Resolving a named dependency among several implementations.
- **AsyncChain (A->B->C, async)**: Asynchronous dependency chain.
- **ScopeOverride (child overrides parent)**: Overriding a dependency in a child scope over a parent.
## Benchmark results
## Features
| Scenario | RunTime (μs) |
|----------------------------------------------------|---------------|
| RegisterAndResolve | 0.4574 |
| ChainSingleton (A->B->C, singleton) | 0.3759 |
| ChainFactory (A->B->C, factory) | 1.3783 |
| NamedResolve (by name) | 0.5193 |
| AsyncChain (A->B->C, async) | 0.5985 |
| ScopeOverride (child overrides parent) | 0.3611 |
- **Unified benchmark structure**: All test scenarios use a unified base mixin for setup/teardown.
- **Flexible CLI parameterization**:
Run benchmarks with custom parameters for chain length, depth, scenarios and formats.
- **Matrix/mass run support**:
Easily run benchmarks for all combinations of chainLength and depth in one run.
- **Machine and human readable output**:
Supports pretty-table, CSV, and JSON for downstream analytics or data storage.
- **Scenario selection**:
Run all or only specific benchmarks via CLI.
## How to run
@@ -30,13 +31,69 @@ All scenarios use the public API capabilities of cherrypick (scope, module, bind
```shell
dart pub get
```
2. Run the benchmarks:
2. Run all benchmarks (with default parameters):
```shell
dart run bin/main.dart
```
A text report with all metrics will be displayed in the console.
### Run with custom parameters
- Mass run in matrix mode (CSV output):
```shell
dart run bin/main.dart --benchmark=chain_singleton --chainCount=10,100 --nestingDepth=5,10 --format=csv
```
- Run only the named resolve scenario:
```shell
dart run bin/main.dart --benchmark=named
```
- See available CLI flags:
```shell
dart run bin/main.dart --help
```
#### Available CLI options
- `--benchmark` (or `-b`) — Scenario to run:
`register`, `chain_singleton`, `chain_factory`, `named`, `override`, `async_chain`, `all` (default)
- `--chainCount` (or `-c`) — Comma-separated chain lengths. E.g. `10,100`
- `--nestingDepth` (or `-d`) — Comma-separated chain depths. E.g. `5,10`
- `--format` (or `-f`) — Result output format: `pretty` (table), `csv`, `json`
- `--help` (or `-h`) — Print help
#### Example output (`--format=csv`)
```
benchmark,chainCount,nestingDepth,elapsed_us
ChainSingleton,10,5,2450000
ChainSingleton,10,10,2624000
ChainSingleton,100,5,2506300
ChainSingleton,100,10,2856900
```
---
To add your custom scenario — just create a new Dart file and declare a class extending BenchmarkBase or AsyncBenchmarkBase, then add its invocation to main.dart.
## Add your own benchmark
1. Create a Dart file with a class inheriting from `BenchmarkBase` or `AsyncBenchmarkBase`.
2. Use the `BenchmarkWithScope` mixin for automatic Scope management if needed.
3. Add your benchmark to bin/main.dart for selection via CLI.
---
## Example for contributors
```dart
class MyBenchmark extends BenchmarkBase with BenchmarkWithScope {
MyBenchmark() : super('My custom');
@override void setup() => setupScope([MyModule()]);
@override void run() { scope.resolve<MyType>(); }
@override void teardown() => teardownScope();
}
```
---
## License
MIT