From 1557b86081ac8e2e9542f1dd7deb61f341cd0fdb Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Mon, 15 Apr 2024 12:33:39 -0300 Subject: [PATCH 01/23] Docs folder standardization and other fixes --- docs/internals.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ psalm.xml | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 docs/internals.md diff --git a/docs/internals.md b/docs/internals.md new file mode 100644 index 00000000..b715d9fb --- /dev/null +++ b/docs/internals.md @@ -0,0 +1,46 @@ +# Internals + +## Unit testing + +The package is tested with [PHPUnit](https://phpunit.de/). To run tests: + +```shell +./vendor/bin/phpunit +``` + +## Mutation testing + +The package tests are checked with [Infection](https://infection.github.io/) mutation framework with +[Infection Static Analysis Plugin](https://github.com/Roave/infection-static-analysis-plugin). To run it: + +```shell +./vendor/bin/roave-infection-static-analysis-plugin +``` + +## Static analysis + +The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis: + +```shell +./vendor/bin/psalm +``` + +## Rector + +Use [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or +use either newest or any specific version of PHP: + +```shell +./vendor/bin/rector +``` + +## Dependencies + +Use [ComposerRequireChecker](https://github.com/maglnet/ComposerRequireChecker) to detect transitive +[Composer](https://getcomposer.org/) dependencies. + +To run the checker, execute the following command: + +```shell +./vendor/bin/composer-require-checker +``` diff --git a/psalm.xml b/psalm.xml index 5ce79f0e..6f6a002d 100644 --- a/psalm.xml +++ b/psalm.xml @@ -3,7 +3,7 @@ errorLevel="1" findUnusedBaselineEntry="true" findUnusedCode="false" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" > From b1089ca06892799630e15d11bbcfe5c2b145104e Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:12:14 -0300 Subject: [PATCH 02/23] update xml files --- psalm.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psalm.xml b/psalm.xml index 6f6a002d..5ce79f0e 100644 --- a/psalm.xml +++ b/psalm.xml @@ -3,7 +3,7 @@ errorLevel="1" findUnusedBaselineEntry="true" findUnusedCode="false" - xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" > From 56528dd966e993c594707509a966c3c2e4619ee3 Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Fri, 19 Apr 2024 11:43:16 -0300 Subject: [PATCH 03/23] Docs folder standardization and other fixes --- LICENSE.md | 8 +-- README.md | 166 +++++++++++++++++++++------------------------- docs/internals.md | 5 +- 3 files changed, 81 insertions(+), 98 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index bc5674fe..6a920d60 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,17 +1,17 @@ -Copyright © 2008 by Yii Software (https://www.yiiframework.com/) +Copyright © 2008 by Yii Software () All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright +* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright +* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Yii Software nor the names of its +* Neither the name of Yii Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/README.md b/README.md index e2a2f0fc..bb4f4d42 100644 --- a/README.md +++ b/README.md @@ -89,17 +89,17 @@ return [ You can define an object in several ways: - * In the simple case, an interface definition maps an id to a particular class. - * A full definition describes how to instantiate a class in more detail: - * `class` has the name of the class to instantiate. - * `__construct()` holds an array of constructor arguments. - * The rest of the config are property values (prefixed with `$`) and method calls, postfixed with `()`. They're +- In the simple case, an interface definition maps an id to a particular class. +- A full definition describes how to instantiate a class in more detail: + - `class` has the name of the class to instantiate. + - `__construct()` holds an array of constructor arguments. + - The rest of the config are property values (prefixed with `$`) and method calls, postfixed with `()`. They're set/called in the order they appear in the array. - * Closures are useful if instantiation is tricky and can better done in code. When using these, arguments are +- Closures are useful if instantiation is tricky and can better done in code. When using these, arguments are auto-wired by type. `ContainerInterface` could be used to get current container instance. - * If it's even more complicated, it's a good idea to move such a code into a +- If it's even more complicated, it's a good idea to move such a code into a factory and reference it as a static call. - * While it's usually not a good idea, you can also set an already +- While it's usually not a good idea, you can also set an already instantiated object into the container. See [yiisoft/definitions](https://github.com/yiisoft/definitions) for more information. @@ -115,11 +115,9 @@ Note, however, that it's bad practice using a container directly. It's much better to rely on auto-wiring as provided by the Injector available from the [yiisoft/injector](https://github.com/yiisoft/injector) package. - ## Using aliases -The DI container supports aliases via the -`Yiisoft\Definitions\Reference` class. +The DI container supports aliases via the `Yiisoft\Definitions\Reference` class. This way you can retrieve objects by a more handy name: ```php @@ -214,7 +212,7 @@ $engine = $composite->get(EngineInterface::class); ## Using service providers A service provider is a special class that's responsible for providing complex -services or groups of dependencies for the container and extensions of existing services. +services or groups of dependencies for the container and extensions of existing services. A provider should extend from `Yiisoft\Di\ServiceProviderInterface` and must contain a `getDefinitions()` and `getExtensions()` methods. It should only provide services for the container @@ -270,7 +268,7 @@ Here you created a service provider responsible for bootstrapping of a car facto An extension is callable that returns a modified service object. In this case you get existing `Garage` service and put a car into the garage by calling the method `setCar()`. -Thus, before applying this provider, you had +Thus, before applying this provider, you had an empty garage and with the help of the extension you fill it. To add this service provider to a container, you can pass either its class or a @@ -357,7 +355,7 @@ $resetter->setResetters([ ``` The callback has access to the private and protected properties of the service instance, so you can set initial state -of the service efficiently without creating a new instance. +of the service efficiently without creating a new instance. You should trigger the reset itself after each request-response cycle. For RoadRunner, it would look like the following: @@ -373,7 +371,7 @@ while ($request = $psr7->acceptRequest()) { } ``` -### Setting resetters in definitions +### Setting resetters in definitions You define the reset state for each service by providing "reset" callback in the following way: @@ -495,11 +493,6 @@ $config = ContainerConfig::create() $container = new Container($config); ``` -## Further reading - -- [Martin Fowler's article](https://martinfowler.com/articles/injection.html). - - # Benchmarks To run benchmarks execute the next command @@ -510,7 +503,7 @@ To run benchmarks execute the next command Result example -``` +```text \Yiisoft\Di\Tests\Benchmark\ContainerBench benchConstructStupid....................I4 [μ Mo]/r: 438.566 435.190 (μs) [μSD μRSD]/r: 9.080μs 2.07% @@ -530,37 +523,40 @@ benchUndefinedNonexistent...............R5 I4 [μ Mo]/r: 0.946 0.942 (μs) [μSD (best [mean mode] worst) = 0.113 [4,483.856 4,486.051] 0.117 (μs) ⅀T: 246,612.096μs μSD/r 43.563μs μRSD/r: 1.336% ``` + > **Warning!** -> These summary statistics can be misleading. +> These summary statistics can be misleading. > You should always verify the individual subject statistics before drawing any conclusions. - +> > **Legend** > -> * μ: Mean time taken by all iterations in variant. -> * Mo: Mode of all iterations in variant. -> * μSD: μ standard deviation. -> * μRSD: μ relative standard deviation. -> * best: Maximum time of all iterations (minimal of all iterations). -> * mean: Mean time taken by all iterations. -> * mode: Mode of all iterations. -> * worst: Minimum time of all iterations (minimal of all iterations). - +> - μ: Mean time taken by all iterations in variant. +> - Mo: Mode of all iterations in variant. +> - μSD: μ standard deviation. +> - μRSD: μ relative standard deviation. +> - best: Maximum time of all iterations (minimal of all iterations). +> - mean: Mean time taken by all iterations. +> - mode: Mode of all iterations. +> - worst: Minimum time of all iterations (minimal of all iterations). ## Command examples -* Default report for all benchmarks that outputs the result to `CSV-file` +- Default report for all benchmarks that outputs the result to `CSV-file` -`$ ./vendor/bin/phpbench run --report=default --progress=dots --output=csv_file` +```shell +./vendor/bin/phpbench run --report=default --progress=dots --output=csv_file +``` Generated MD-file example +```text >DI benchmark report >=================== > >### suite: 1343b1dc0589cb4e985036d14b3e12cb430a975b, date: 2020-02-21, stime: 16:02:45 > >benchmark | subject | set | revs | iter | mem_peak | time_rev | comp_z_value | comp_deviation -> --- | --- | --- | --- | --- | --- | --- | --- | --- +> --- | --- | --- | --- | --- | --- | --- | --- | --- >ContainerBench | benchConstructStupid | 0 | 1000 | 0 | 1,416,784b | 210.938μs | -1.48σ | -1.1% >ContainerBench | benchConstructStupid | 0 | 1000 | 1 | 1,416,784b | 213.867μs | +0.37σ | +0.27% >ContainerBench | benchConstructStupid | 0 | 1000 | 2 | 1,416,784b | 212.890μs | -0.25σ | -0.18% @@ -581,34 +577,37 @@ Generated MD-file example > **Legend** > -> * benchmark: Benchmark class. -> * subject: Benchmark class method. -> * set: Set of data (provided by ParamProvider). -> * revs: Number of revolutions (represent the number of times that the code is executed). -> * iter: Number of iteration. -> * mem_peak: (mean) Peak memory used by iteration as retrieved by memory_get_peak_usage. -> * time_rev: Mean time taken by all iterations in variant. -> * comp_z_value: Z-score. -> * comp_deviation: Relative deviation (margin of error). +> - benchmark: Benchmark class. +> - subject: Benchmark class method. +> - set: Set of data (provided by ParamProvider). +> - revs: Number of revolutions (represent the number of times that the code is executed). +> - iter: Number of iteration. +> - mem_peak: (mean) Peak memory used by iteration as retrieved by memory_get_peak_usage. +> - time_rev: Mean time taken by all iterations in variant. +> - comp_z_value: Z-score. +> - comp_deviation: Relative deviation (margin of error). +``` -* Aggregate report for the `lookup` group that outputs the result to `console` and `CSV-file` +- Aggregate report for the `lookup` group that outputs the result to `console` and `CSV-file` -`$ ./vendor/bin/phpbench run --report=aggregate --progress=dots --output=csv_file --output=console --group=lookup -` +```shell +./vendor/bin/phpbench run --report=aggregate --progress=dots --output=csv_file --output=console --group=lookup +``` >**Notice** -> -> Available groups: `construct` `lookup` `has` +> +> Available groups: `construct` `lookup` `has` Generated MD-file example +```text > DI benchmark report > =================== > >### suite: 1343b1d2654a3819c72a96d236302b70a504dac7, date: 2020-02-21, stime: 13:27:32 > >benchmark | subject | set | revs | its | mem_peak | best | mean | mode | worst | stdev | rstdev | diff -> --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- +> --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- >ContainerBench | benchSequentialLookups | 0 | 1000 | 5 | 1,454,024b | 168.945μs | 170.117μs | 169.782μs | 171.875μs | 0.957μs | 0.56% | 1.00x >ContainerBench | benchSequentialLookups | 1 | 1000 | 5 | 1,445,296b | 3,347.656μs | 3,384.961μs | 3,390.411μs | 3,414.062μs | 21.823μs | 0.64% | 19.90x >ContainerBench | benchSequentialLookups | 2 | 1000 | 5 | 1,445,568b | 3,420.898μs | 3,488.477μs | 3,447.260μs | 3,657.227μs | 85.705μs | 2.46% | 20.51x @@ -621,53 +620,31 @@ Generated MD-file example > **Legend** > -> * benchmark: Benchmark class. -> * subject: Benchmark class method. -> * set: Set of data (provided by ParamProvider). -> * revs: Number of revolutions (represent the number of times that the code is executed). -> * its: Number of iterations (one measurement for each iteration). -> * mem_peak: (mean) Peak memory used by each iteration as retrieved by memory_get_peak_usage. -> * best: Maximum time of all iterations in variant. -> * mean: Mean time taken by all iterations in variant. -> * mode: Mode of all iterations in variant. -> * worst: Minimum time of all iterations in variant. -> * stdev: Standard deviation. -> * rstdev: The relative standard deviation. -> * diff: Difference between variants in a single group. - -## Testing - -### Unit testing - -The package is tested with [PHPUnit](https://phpunit.de/). To run tests: - -```shell -./vendor/bin/phpunit +> - benchmark: Benchmark class. +> - subject: Benchmark class method. +> - set: Set of data (provided by ParamProvider). +> - revs: Number of revolutions (represent the number of times that the code is executed). +> - its: Number of iterations (one measurement for each iteration). +> - mem_peak: (mean) Peak memory used by each iteration as retrieved by memory_get_peak_usage. +> - best: Maximum time of all iterations in variant. +> - mean: Mean time taken by all iterations in variant. +> - mode: Mode of all iterations in variant. +> - worst: Minimum time of all iterations in variant. +> - stdev: Standard deviation. +> - rstdev: The relative standard deviation. +> - diff: Difference between variants in a single group. ``` -### Mutation testing +## Documentation -The package tests are checked with [Infection](https://infection.github.io/) mutation framework with -[Infection Static Analysis Plugin](https://github.com/Roave/infection-static-analysis-plugin). To run it: +- Further reading: [Martin Fowler's article "Inversion of Control Containers and the Dependency Injection pattern"](https://martinfowler.com/articles/injection.html). -```shell -./vendor/bin/roave-infection-static-analysis-plugin -``` - -### Static analysis +- More information can be found in the [Internals.](docs/internals.md) -The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis: +## Support -```shell -./vendor/bin/psalm -``` - -## License - -The Yii Dependency Injection is free software. It's released under the terms of the BSD License. -Please see [`LICENSE`](./LICENSE.md) for more information. - -Maintained by [Yii Software](https://www.yiiframework.com/). +If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that. +You may also check out other [Yii Community Resources](https://www.yiiframework.com/community). ## Support the project @@ -680,3 +657,10 @@ Maintained by [Yii Software](https://www.yiiframework.com/). [![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat&logo=telegram)](https://t.me/yii3en) [![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat&logo=facebook&logoColor=ffffff)](https://www.facebook.com/groups/yiitalk) [![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat&logo=slack)](https://yiiframework.com/go/slack) + +## License + +The Yii Access is free software. It is released under the terms of the BSD License. +Please see [`LICENSE`](./LICENSE.md) for more information. + +Maintained by [Yii Software](https://www.yiiframework.com/). diff --git a/docs/internals.md b/docs/internals.md index b715d9fb..8dc4049f 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -34,10 +34,9 @@ use either newest or any specific version of PHP: ./vendor/bin/rector ``` -## Dependencies +## Composer require checker -Use [ComposerRequireChecker](https://github.com/maglnet/ComposerRequireChecker) to detect transitive -[Composer](https://getcomposer.org/) dependencies. +This package uses [composer-require-checker](https://github.com/maglnet/ComposerRequireChecker) to check if all dependencies are correctly defined in `composer.json`. To run the checker, execute the following command: From b1caab58db7696ab471e7594e435cc3f016dd42f Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Sun, 21 Apr 2024 06:32:37 -0300 Subject: [PATCH 04/23] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bb4f4d42..539a9943 100644 --- a/README.md +++ b/README.md @@ -639,7 +639,7 @@ Generated MD-file example - Further reading: [Martin Fowler's article "Inversion of Control Containers and the Dependency Injection pattern"](https://martinfowler.com/articles/injection.html). -- More information can be found in the [Internals.](docs/internals.md) +- [Internals](docs/internals.md) ## Support From 2aa9314278e1658df23d871f2917f9e304ae9df1 Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Wed, 24 Apr 2024 10:24:30 -0300 Subject: [PATCH 05/23] Update README.md --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 539a9943..0a5d3b66 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -

Yii Dependency Injection

+

Yii DI


@@ -620,19 +620,19 @@ Generated MD-file example > **Legend** > -> - benchmark: Benchmark class. -> - subject: Benchmark class method. -> - set: Set of data (provided by ParamProvider). -> - revs: Number of revolutions (represent the number of times that the code is executed). -> - its: Number of iterations (one measurement for each iteration). -> - mem_peak: (mean) Peak memory used by each iteration as retrieved by memory_get_peak_usage. -> - best: Maximum time of all iterations in variant. -> - mean: Mean time taken by all iterations in variant. -> - mode: Mode of all iterations in variant. -> - worst: Minimum time of all iterations in variant. -> - stdev: Standard deviation. -> - rstdev: The relative standard deviation. -> - diff: Difference between variants in a single group. +> * benchmark: Benchmark class. +> * subject: Benchmark class method. +> * set: Set of data (provided by ParamProvider). +> * revs: Number of revolutions (represent the number of times that the code is executed). +> * its: Number of iterations (one measurement for each iteration). +> * mem_peak: (mean) Peak memory used by each iteration as retrieved by memory_get_peak_usage. +> * best: Maximum time of all iterations in variant. +> * mean: Mean time taken by all iterations in variant. +> * mode: Mode of all iterations in variant. +> * worst: Minimum time of all iterations in variant. +> * stdev: Standard deviation. +> * rstdev: The relative standard deviation. +> * diff: Difference between variants in a single group. ``` ## Documentation @@ -660,7 +660,7 @@ You may also check out other [Yii Community Resources](https://www.yiiframework. ## License -The Yii Access is free software. It is released under the terms of the BSD License. +The Yii DI is free software. It is released under the terms of the BSD License. Please see [`LICENSE`](./LICENSE.md) for more information. Maintained by [Yii Software](https://www.yiiframework.com/). From 397dfeb8152eee3ffe4dcc0232c94f5ee5be0152 Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:13:49 -0300 Subject: [PATCH 06/23] Update README.md Co-authored-by: Alexander Makarov --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a5d3b66..f81a8278 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -

Yii DI

+

Yii Dependency Injection


From 476d8093d6086d8a5f84cb1add98f3c757cea759 Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:19:47 -0300 Subject: [PATCH 07/23] Update file --- README.md | 2 -- docs/internals.md | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f81a8278..b44da4f8 100644 --- a/README.md +++ b/README.md @@ -637,8 +637,6 @@ Generated MD-file example ## Documentation -- Further reading: [Martin Fowler's article "Inversion of Control Containers and the Dependency Injection pattern"](https://martinfowler.com/articles/injection.html). - - [Internals](docs/internals.md) ## Support diff --git a/docs/internals.md b/docs/internals.md index 8dc4049f..52fc67e8 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -1,5 +1,7 @@ # Internals +- Further reading: [Martin Fowler's article "Inversion of Control Containers and the Dependency Injection pattern"](https://martinfowler.com/articles/injection.html). + ## Unit testing The package is tested with [PHPUnit](https://phpunit.de/). To run tests: @@ -34,7 +36,7 @@ use either newest or any specific version of PHP: ./vendor/bin/rector ``` -## Composer require checker +## Dependencies This package uses [composer-require-checker](https://github.com/maglnet/ComposerRequireChecker) to check if all dependencies are correctly defined in `composer.json`. From 13606ea5d025c62f2c32e460edf9377a38feb0e6 Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:21:37 -0300 Subject: [PATCH 08/23] Update internals.md --- docs/internals.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/internals.md b/docs/internals.md index 52fc67e8..2c4e91ac 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -1,6 +1,6 @@ # Internals -- Further reading: [Martin Fowler's article "Inversion of Control Containers and the Dependency Injection pattern"](https://martinfowler.com/articles/injection.html). +Further reading: [Martin Fowler's article "Inversion of Control Containers and the Dependency Injection pattern"](https://martinfowler.com/articles/injection.html). ## Unit testing From 93fcfe8dd94e18cb63c27b9d8d6a9f3e9ac1629a Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Thu, 25 Apr 2024 10:51:53 -0300 Subject: [PATCH 09/23] Update internals.md --- docs/internals.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/internals.md b/docs/internals.md index 2c4e91ac..565eff98 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -1,5 +1,6 @@ # Internals +## Further reading Further reading: [Martin Fowler's article "Inversion of Control Containers and the Dependency Injection pattern"](https://martinfowler.com/articles/injection.html). ## Unit testing From 6066b5809afc31553a714ce904749ef7b808b70a Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Thu, 25 Apr 2024 10:55:21 -0300 Subject: [PATCH 10/23] Update internals.md --- docs/internals.md | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/docs/internals.md b/docs/internals.md index 565eff98..8b2296ec 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -1,7 +1,9 @@ # Internals ## Further reading -Further reading: [Martin Fowler's article "Inversion of Control Containers and the Dependency Injection pattern"](https://martinfowler.com/articles/injection.html). + +- [Martin Fowler's article](https://martinfowler.com/articles/injection.html). + ## Unit testing @@ -27,22 +29,3 @@ The code is statically analyzed with [Psalm](https://psalm.dev/). To run static ```shell ./vendor/bin/psalm ``` - -## Rector - -Use [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or -use either newest or any specific version of PHP: - -```shell -./vendor/bin/rector -``` - -## Dependencies - -This package uses [composer-require-checker](https://github.com/maglnet/ComposerRequireChecker) to check if all dependencies are correctly defined in `composer.json`. - -To run the checker, execute the following command: - -```shell -./vendor/bin/composer-require-checker -``` From 001cfa106ec272758fa81a920f58dbfe617993ec Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:04:16 -0300 Subject: [PATCH 11/23] Update file --- README.md | 5 +++++ docs/internals.md | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b44da4f8..c4d5bf3f 100644 --- a/README.md +++ b/README.md @@ -493,6 +493,11 @@ $config = ContainerConfig::create() $container = new Container($config); ``` +## Further reading + +- [Martin Fowler's article](https://martinfowler.com/articles/injection.html). + + # Benchmarks To run benchmarks execute the next command diff --git a/docs/internals.md b/docs/internals.md index 8b2296ec..b37b5b8d 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -1,10 +1,5 @@ # Internals -## Further reading - -- [Martin Fowler's article](https://martinfowler.com/articles/injection.html). - - ## Unit testing The package is tested with [PHPUnit](https://phpunit.de/). To run tests: From 1e1bc601529a4e5311d3ca83d5d4337c52a6931a Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:07:48 -0300 Subject: [PATCH 12/23] Update internals.md --- docs/internals.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/internals.md b/docs/internals.md index b37b5b8d..775532e1 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -24,3 +24,23 @@ The code is statically analyzed with [Psalm](https://psalm.dev/). To run static ```shell ./vendor/bin/psalm ``` + +## Rector + +Use [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or +use either newest or any specific version of PHP: + +```shell +./vendor/bin/rector +``` + +## Dependencies + +Use [ComposerRequireChecker](https://github.com/maglnet/ComposerRequireChecker) to detect transitive +[Composer](https://getcomposer.org/) dependencies. + +To run the checker, execute the following command: + +```shell +./vendor/bin/composer-require-checker +``` \ No newline at end of file From d90d43ae3d7dbb34012332d97c503f091d0dbf49 Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:09:44 -0300 Subject: [PATCH 13/23] Update internals.md --- docs/internals.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/internals.md b/docs/internals.md index 775532e1..b715d9fb 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -43,4 +43,4 @@ To run the checker, execute the following command: ```shell ./vendor/bin/composer-require-checker -``` \ No newline at end of file +``` From d0f44ac613bdf6f756a9f9404ac986a07d3ac340 Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:44:19 -0300 Subject: [PATCH 14/23] Update README.md Co-authored-by: Sergei Predvoditelev --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index c4d5bf3f..608129ca 100644 --- a/README.md +++ b/README.md @@ -532,7 +532,6 @@ benchUndefinedNonexistent...............R5 I4 [μ Mo]/r: 0.946 0.942 (μs) [μSD > **Warning!** > These summary statistics can be misleading. > You should always verify the individual subject statistics before drawing any conclusions. -> > **Legend** > > - μ: Mean time taken by all iterations in variant. From db6ca7a764e53351cea850ed058725e918939b6c Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:44:52 -0300 Subject: [PATCH 15/23] Update README.md Co-authored-by: Sergei Predvoditelev --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 608129ca..697c6d73 100644 --- a/README.md +++ b/README.md @@ -643,8 +643,6 @@ Generated MD-file example - [Internals](docs/internals.md) -## Support - If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that. You may also check out other [Yii Community Resources](https://www.yiiframework.com/community). From 688871884ce52d4259217e021585688ca7c25edc Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:46:10 -0300 Subject: [PATCH 16/23] Update README.md Co-authored-by: Sergei Predvoditelev --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 697c6d73..e8e351e4 100644 --- a/README.md +++ b/README.md @@ -660,7 +660,7 @@ You may also check out other [Yii Community Resources](https://www.yiiframework. ## License -The Yii DI is free software. It is released under the terms of the BSD License. +The Yii Dependency Injection is free software. It is released under the terms of the BSD License. Please see [`LICENSE`](./LICENSE.md) for more information. Maintained by [Yii Software](https://www.yiiframework.com/). From 225253d90f26ae0075034d6f576db2d1ae32e525 Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:46:48 -0300 Subject: [PATCH 17/23] Update docs/internals.md Co-authored-by: Sergei Predvoditelev --- docs/internals.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/internals.md b/docs/internals.md index b715d9fb..85e20e4c 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -37,9 +37,7 @@ use either newest or any specific version of PHP: ## Dependencies Use [ComposerRequireChecker](https://github.com/maglnet/ComposerRequireChecker) to detect transitive -[Composer](https://getcomposer.org/) dependencies. - -To run the checker, execute the following command: +[Composer](https://getcomposer.org/) dependencies: ```shell ./vendor/bin/composer-require-checker From 872bb8503daf5037579d9763ec1d3d5455076eca Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:47:10 -0300 Subject: [PATCH 18/23] Update docs/internals.md Co-authored-by: Sergei Predvoditelev --- docs/internals.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/internals.md b/docs/internals.md index 85e20e4c..ea202fe7 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -25,7 +25,7 @@ The code is statically analyzed with [Psalm](https://psalm.dev/). To run static ./vendor/bin/psalm ``` -## Rector +## Code style Use [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or use either newest or any specific version of PHP: From 13ec19daca9d09f44647cf0c126569dfb81ff120 Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Fri, 26 Apr 2024 05:59:15 -0300 Subject: [PATCH 19/23] Update 'internals.md' --- LICENSE.md | 12 ++++++------ docs/internals.md | 18 ------------------ 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 6a920d60..fa6ef0f9 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -6,14 +6,14 @@ modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. * Neither the name of Yii Software nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT diff --git a/docs/internals.md b/docs/internals.md index ea202fe7..b37b5b8d 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -24,21 +24,3 @@ The code is statically analyzed with [Psalm](https://psalm.dev/). To run static ```shell ./vendor/bin/psalm ``` - -## Code style - -Use [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or -use either newest or any specific version of PHP: - -```shell -./vendor/bin/rector -``` - -## Dependencies - -Use [ComposerRequireChecker](https://github.com/maglnet/ComposerRequireChecker) to detect transitive -[Composer](https://getcomposer.org/) dependencies: - -```shell -./vendor/bin/composer-require-checker -``` From 86bf39ec860f4104e3b143590c928763c9c1919e Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Fri, 26 Apr 2024 06:10:53 -0300 Subject: [PATCH 20/23] Revert "Update internals.md" This reverts commit d90d43ae3d7dbb34012332d97c503f091d0dbf49. --- docs/internals.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/internals.md b/docs/internals.md index b37b5b8d..b715d9fb 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -24,3 +24,23 @@ The code is statically analyzed with [Psalm](https://psalm.dev/). To run static ```shell ./vendor/bin/psalm ``` + +## Rector + +Use [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or +use either newest or any specific version of PHP: + +```shell +./vendor/bin/rector +``` + +## Dependencies + +Use [ComposerRequireChecker](https://github.com/maglnet/ComposerRequireChecker) to detect transitive +[Composer](https://getcomposer.org/) dependencies. + +To run the checker, execute the following command: + +```shell +./vendor/bin/composer-require-checker +``` From 6bc4c8d0c31d1b7faee629387b039a8818b6155e Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Fri, 26 Apr 2024 06:20:03 -0300 Subject: [PATCH 21/23] Update LICENSE.md --- LICENSE.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index fa6ef0f9..6a920d60 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -6,14 +6,14 @@ modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. * Neither the name of Yii Software nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT From ae862ea23d20b2a220d3f69a5faeec97f47b3d97 Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Fri, 26 Apr 2024 06:29:11 -0300 Subject: [PATCH 22/23] Update file --- LICENSE.md | 12 ++++++------ README.md | 5 ----- docs/internals.md | 4 ++++ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 6a920d60..fa6ef0f9 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -6,14 +6,14 @@ modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. * Neither the name of Yii Software nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT diff --git a/README.md b/README.md index e8e351e4..cdeb8f3b 100644 --- a/README.md +++ b/README.md @@ -493,11 +493,6 @@ $config = ContainerConfig::create() $container = new Container($config); ``` -## Further reading - -- [Martin Fowler's article](https://martinfowler.com/articles/injection.html). - - # Benchmarks To run benchmarks execute the next command diff --git a/docs/internals.md b/docs/internals.md index b715d9fb..1f46e487 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -1,5 +1,9 @@ # Internals +## Further reading + +- [Martin Fowler's article](https://martinfowler.com/articles/injection.html). + ## Unit testing The package is tested with [PHPUnit](https://phpunit.de/). To run tests: From a12084907a55be5684d9fc2e98a8ccc12a8dad44 Mon Sep 17 00:00:00 2001 From: Luiz Marin <67489841+luizcmarin@users.noreply.github.com> Date: Fri, 26 Apr 2024 09:29:29 -0300 Subject: [PATCH 23/23] Update file --- README.md | 141 ---------------------------------------------- docs/internals.md | 141 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+), 141 deletions(-) diff --git a/README.md b/README.md index cdeb8f3b..56da0933 100644 --- a/README.md +++ b/README.md @@ -493,147 +493,6 @@ $config = ContainerConfig::create() $container = new Container($config); ``` -# Benchmarks - -To run benchmarks execute the next command - -```shell -./vendor/bin/phpbench run -``` - -Result example - -```text -\Yiisoft\Di\Tests\Benchmark\ContainerBench - -benchConstructStupid....................I4 [μ Mo]/r: 438.566 435.190 (μs) [μSD μRSD]/r: 9.080μs 2.07% -benchConstructSmart.....................I4 [μ Mo]/r: 470.958 468.942 (μs) [μSD μRSD]/r: 2.848μs 0.60% -benchSequentialLookups # 0..............R5 I4 [μ Mo]/r: 2,837.000 2,821.636 (μs) [μSD μRSD]/r: 34.123μs 1.20% -benchSequentialLookups # 1..............R1 I0 [μ Mo]/r: 12,253.600 12,278.859 (μs) [μSD μRSD]/r: 69.087μs 0.56% -benchRandomLookups # 0..................R5 I4 [μ Mo]/r: 3,142.200 3,111.290 (μs) [μSD μRSD]/r: 87.639μs 2.79% -benchRandomLookups # 1..................R1 I2 [μ Mo]/r: 13,298.800 13,337.170 (μs) [μSD μRSD]/r: 103.891μs 0.78% -benchRandomLookupsComposite # 0.........R1 I3 [μ Mo]/r: 3,351.600 3,389.104 (μs) [μSD μRSD]/r: 72.516μs 2.16% -benchRandomLookupsComposite # 1.........R1 I4 [μ Mo]/r: 13,528.200 13,502.881 (μs) [μSD μRSD]/r: 99.997μs 0.74% -\Yiisoft\Di\Tests\Benchmark\ContainerMethodHasBench - -benchPredefinedExisting.................R1 I4 [μ Mo]/r: 0.115 0.114 (μs) [μSD μRSD]/r: 0.001μs 1.31% -benchUndefinedExisting..................R5 I4 [μ Mo]/r: 0.436 0.432 (μs) [μSD μRSD]/r: 0.008μs 1.89% -benchUndefinedNonexistent...............R5 I4 [μ Mo]/r: 0.946 0.942 (μs) [μSD μRSD]/r: 0.006μs 0.59% -8 subjects, 55 iterations, 5,006 revs, 0 rejects, 0 failures, 0 warnings -(best [mean mode] worst) = 0.113 [4,483.856 4,486.051] 0.117 (μs) -⅀T: 246,612.096μs μSD/r 43.563μs μRSD/r: 1.336% -``` - -> **Warning!** -> These summary statistics can be misleading. -> You should always verify the individual subject statistics before drawing any conclusions. -> **Legend** -> -> - μ: Mean time taken by all iterations in variant. -> - Mo: Mode of all iterations in variant. -> - μSD: μ standard deviation. -> - μRSD: μ relative standard deviation. -> - best: Maximum time of all iterations (minimal of all iterations). -> - mean: Mean time taken by all iterations. -> - mode: Mode of all iterations. -> - worst: Minimum time of all iterations (minimal of all iterations). - -## Command examples - -- Default report for all benchmarks that outputs the result to `CSV-file` - -```shell -./vendor/bin/phpbench run --report=default --progress=dots --output=csv_file -``` - -Generated MD-file example - -```text ->DI benchmark report ->=================== -> ->### suite: 1343b1dc0589cb4e985036d14b3e12cb430a975b, date: 2020-02-21, stime: 16:02:45 -> ->benchmark | subject | set | revs | iter | mem_peak | time_rev | comp_z_value | comp_deviation -> --- | --- | --- | --- | --- | --- | --- | --- | --- ->ContainerBench | benchConstructStupid | 0 | 1000 | 0 | 1,416,784b | 210.938μs | -1.48σ | -1.1% ->ContainerBench | benchConstructStupid | 0 | 1000 | 1 | 1,416,784b | 213.867μs | +0.37σ | +0.27% ->ContainerBench | benchConstructStupid | 0 | 1000 | 2 | 1,416,784b | 212.890μs | -0.25σ | -0.18% ->ContainerBench | benchConstructStupid | 0 | 1000 | 3 | 1,416,784b | 215.820μs | +1.60σ | +1.19% ->ContainerBench | benchConstructStupid | 0 | 1000 | 4 | 1,416,784b | 212.891μs | -0.25σ | -0.18% ->ContainerBench | benchConstructSmart | 0 | 1000 | 0 | 1,426,280b | 232.422μs | -1.03σ | -0.5% ->ContainerBench | benchConstructSmart | 0 | 1000 | 1 | 1,426,280b | 232.422μs | -1.03σ | -0.5% ->ContainerBench | benchConstructSmart | 0 | 1000 | 2 | 1,426,280b | 233.398μs | -0.17σ | -0.08% ->ContainerBench | benchConstructSmart | 0 | 1000 | 3 | 1,426,280b | 234.375μs | +0.69σ | +0.33% ->ContainerBench | benchConstructSmart | 0 | 1000 | 4 | 1,426,280b | 235.351μs | +1.54σ | +0.75% ->`... skipped` | `...` | `...` | `...` | `...` | `...` | `...` | `...` | `...` ->ContainerMethodHasBench | benchPredefinedExisting | 0 | 1000 | 0 | 1,216,144b | 81.055μs | -0.91σ | -1.19% ->ContainerMethodHasBench | benchPredefinedExisting | 0 | 1000 | 1 | 1,216,144b | 83.985μs | +1.83σ | +2.38% ->ContainerMethodHasBench | benchPredefinedExisting | 0 | 1000 | 2 | 1,216,144b | 82.032μs | 0.00σ | 0.00% ->ContainerMethodHasBench | benchPredefinedExisting | 0 | 1000 | 3 | 1,216,144b | 82.031μs | 0.00σ | 0.00% ->ContainerMethodHasBench | benchPredefinedExisting | 0 | 1000 | 4 | 1,216,144b | 81.055μs | -0.91σ | -1.19% ->`... skipped` | `...` | `...` | `...` | `...` | `...` | `...` | `...` | `...` - -> **Legend** -> -> - benchmark: Benchmark class. -> - subject: Benchmark class method. -> - set: Set of data (provided by ParamProvider). -> - revs: Number of revolutions (represent the number of times that the code is executed). -> - iter: Number of iteration. -> - mem_peak: (mean) Peak memory used by iteration as retrieved by memory_get_peak_usage. -> - time_rev: Mean time taken by all iterations in variant. -> - comp_z_value: Z-score. -> - comp_deviation: Relative deviation (margin of error). -``` - -- Aggregate report for the `lookup` group that outputs the result to `console` and `CSV-file` - -```shell -./vendor/bin/phpbench run --report=aggregate --progress=dots --output=csv_file --output=console --group=lookup -``` - ->**Notice** -> -> Available groups: `construct` `lookup` `has` - -Generated MD-file example - -```text -> DI benchmark report -> =================== -> ->### suite: 1343b1d2654a3819c72a96d236302b70a504dac7, date: 2020-02-21, stime: 13:27:32 -> ->benchmark | subject | set | revs | its | mem_peak | best | mean | mode | worst | stdev | rstdev | diff -> --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- ->ContainerBench | benchSequentialLookups | 0 | 1000 | 5 | 1,454,024b | 168.945μs | 170.117μs | 169.782μs | 171.875μs | 0.957μs | 0.56% | 1.00x ->ContainerBench | benchSequentialLookups | 1 | 1000 | 5 | 1,445,296b | 3,347.656μs | 3,384.961μs | 3,390.411μs | 3,414.062μs | 21.823μs | 0.64% | 19.90x ->ContainerBench | benchSequentialLookups | 2 | 1000 | 5 | 1,445,568b | 3,420.898μs | 3,488.477μs | 3,447.260μs | 3,657.227μs | 85.705μs | 2.46% | 20.51x ->ContainerBench | benchRandomLookups | 0 | 1000 | 5 | 1,454,024b | 169.922μs | 171.875μs | 171.871μs | 173.828μs | 1.381μs | 0.80% | 1.01x ->ContainerBench | benchRandomLookups | 1 | 1000 | 5 | 1,445,296b | 3,353.515μs | 3,389.844μs | 3,377.299μs | 3,446.289μs | 31.598μs | 0.93% | 19.93x ->ContainerBench | benchRandomLookups | 2 | 1000 | 5 | 1,445,568b | 3,445.313μs | 3,587.696μs | 3,517.823μs | 3,749.023μs | 115.850μs | 3.23% | 21.09x ->ContainerBench | benchRandomLookupsComposite | 0 | 1000 | 5 | 1,454,032b | 297.852μs | 299.610μs | 298.855μs | 302.734μs | 1.680μs | 0.56% | 1.76x ->ContainerBench | benchRandomLookupsComposite | 1 | 1000 | 5 | 1,445,880b | 3,684.570μs | 3,708.984μs | 3,695.731μs | 3,762.695μs | 28.297μs | 0.76% | 21.80x ->ContainerBench | benchRandomLookupsComposite | 2 | 1000 | 5 | 1,446,152b | 3,668.946μs | 3,721.680μs | 3,727.407μs | 3,765.625μs | 30.881μs | 0.83% | 21.88x - -> **Legend** -> -> * benchmark: Benchmark class. -> * subject: Benchmark class method. -> * set: Set of data (provided by ParamProvider). -> * revs: Number of revolutions (represent the number of times that the code is executed). -> * its: Number of iterations (one measurement for each iteration). -> * mem_peak: (mean) Peak memory used by each iteration as retrieved by memory_get_peak_usage. -> * best: Maximum time of all iterations in variant. -> * mean: Mean time taken by all iterations in variant. -> * mode: Mode of all iterations in variant. -> * worst: Minimum time of all iterations in variant. -> * stdev: Standard deviation. -> * rstdev: The relative standard deviation. -> * diff: Difference between variants in a single group. -``` - ## Documentation - [Internals](docs/internals.md) diff --git a/docs/internals.md b/docs/internals.md index 1f46e487..d1979f72 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -1,5 +1,146 @@ # Internals +# Benchmarks + +To run benchmarks execute the next command + +```shell +./vendor/bin/phpbench run +``` + +Result example + +```text +\Yiisoft\Di\Tests\Benchmark\ContainerBench + +benchConstructStupid....................I4 [μ Mo]/r: 438.566 435.190 (μs) [μSD μRSD]/r: 9.080μs 2.07% +benchConstructSmart.....................I4 [μ Mo]/r: 470.958 468.942 (μs) [μSD μRSD]/r: 2.848μs 0.60% +benchSequentialLookups # 0..............R5 I4 [μ Mo]/r: 2,837.000 2,821.636 (μs) [μSD μRSD]/r: 34.123μs 1.20% +benchSequentialLookups # 1..............R1 I0 [μ Mo]/r: 12,253.600 12,278.859 (μs) [μSD μRSD]/r: 69.087μs 0.56% +benchRandomLookups # 0..................R5 I4 [μ Mo]/r: 3,142.200 3,111.290 (μs) [μSD μRSD]/r: 87.639μs 2.79% +benchRandomLookups # 1..................R1 I2 [μ Mo]/r: 13,298.800 13,337.170 (μs) [μSD μRSD]/r: 103.891μs 0.78% +benchRandomLookupsComposite # 0.........R1 I3 [μ Mo]/r: 3,351.600 3,389.104 (μs) [μSD μRSD]/r: 72.516μs 2.16% +benchRandomLookupsComposite # 1.........R1 I4 [μ Mo]/r: 13,528.200 13,502.881 (μs) [μSD μRSD]/r: 99.997μs 0.74% +\Yiisoft\Di\Tests\Benchmark\ContainerMethodHasBench + +benchPredefinedExisting.................R1 I4 [μ Mo]/r: 0.115 0.114 (μs) [μSD μRSD]/r: 0.001μs 1.31% +benchUndefinedExisting..................R5 I4 [μ Mo]/r: 0.436 0.432 (μs) [μSD μRSD]/r: 0.008μs 1.89% +benchUndefinedNonexistent...............R5 I4 [μ Mo]/r: 0.946 0.942 (μs) [μSD μRSD]/r: 0.006μs 0.59% +8 subjects, 55 iterations, 5,006 revs, 0 rejects, 0 failures, 0 warnings +(best [mean mode] worst) = 0.113 [4,483.856 4,486.051] 0.117 (μs) +⅀T: 246,612.096μs μSD/r 43.563μs μRSD/r: 1.336% +``` + +> **Warning!** +> These summary statistics can be misleading. +> You should always verify the individual subject statistics before drawing any conclusions. +> **Legend** +> +> - μ: Mean time taken by all iterations in variant. +> - Mo: Mode of all iterations in variant. +> - μSD: μ standard deviation. +> - μRSD: μ relative standard deviation. +> - best: Maximum time of all iterations (minimal of all iterations). +> - mean: Mean time taken by all iterations. +> - mode: Mode of all iterations. +> - worst: Minimum time of all iterations (minimal of all iterations). + +## Command examples + +- Default report for all benchmarks that outputs the result to `CSV-file` + +```shell +./vendor/bin/phpbench run --report=default --progress=dots --output=csv_file +``` + +Generated MD-file example + +```text +>DI benchmark report +>=================== +> +>### suite: 1343b1dc0589cb4e985036d14b3e12cb430a975b, date: 2020-02-21, stime: 16:02:45 +> +>benchmark | subject | set | revs | iter | mem_peak | time_rev | comp_z_value | comp_deviation +> --- | --- | --- | --- | --- | --- | --- | --- | --- +>ContainerBench | benchConstructStupid | 0 | 1000 | 0 | 1,416,784b | 210.938μs | -1.48σ | -1.1% +>ContainerBench | benchConstructStupid | 0 | 1000 | 1 | 1,416,784b | 213.867μs | +0.37σ | +0.27% +>ContainerBench | benchConstructStupid | 0 | 1000 | 2 | 1,416,784b | 212.890μs | -0.25σ | -0.18% +>ContainerBench | benchConstructStupid | 0 | 1000 | 3 | 1,416,784b | 215.820μs | +1.60σ | +1.19% +>ContainerBench | benchConstructStupid | 0 | 1000 | 4 | 1,416,784b | 212.891μs | -0.25σ | -0.18% +>ContainerBench | benchConstructSmart | 0 | 1000 | 0 | 1,426,280b | 232.422μs | -1.03σ | -0.5% +>ContainerBench | benchConstructSmart | 0 | 1000 | 1 | 1,426,280b | 232.422μs | -1.03σ | -0.5% +>ContainerBench | benchConstructSmart | 0 | 1000 | 2 | 1,426,280b | 233.398μs | -0.17σ | -0.08% +>ContainerBench | benchConstructSmart | 0 | 1000 | 3 | 1,426,280b | 234.375μs | +0.69σ | +0.33% +>ContainerBench | benchConstructSmart | 0 | 1000 | 4 | 1,426,280b | 235.351μs | +1.54σ | +0.75% +>`... skipped` | `...` | `...` | `...` | `...` | `...` | `...` | `...` | `...` +>ContainerMethodHasBench | benchPredefinedExisting | 0 | 1000 | 0 | 1,216,144b | 81.055μs | -0.91σ | -1.19% +>ContainerMethodHasBench | benchPredefinedExisting | 0 | 1000 | 1 | 1,216,144b | 83.985μs | +1.83σ | +2.38% +>ContainerMethodHasBench | benchPredefinedExisting | 0 | 1000 | 2 | 1,216,144b | 82.032μs | 0.00σ | 0.00% +>ContainerMethodHasBench | benchPredefinedExisting | 0 | 1000 | 3 | 1,216,144b | 82.031μs | 0.00σ | 0.00% +>ContainerMethodHasBench | benchPredefinedExisting | 0 | 1000 | 4 | 1,216,144b | 81.055μs | -0.91σ | -1.19% +>`... skipped` | `...` | `...` | `...` | `...` | `...` | `...` | `...` | `...` + +> **Legend** +> +> - benchmark: Benchmark class. +> - subject: Benchmark class method. +> - set: Set of data (provided by ParamProvider). +> - revs: Number of revolutions (represent the number of times that the code is executed). +> - iter: Number of iteration. +> - mem_peak: (mean) Peak memory used by iteration as retrieved by memory_get_peak_usage. +> - time_rev: Mean time taken by all iterations in variant. +> - comp_z_value: Z-score. +> - comp_deviation: Relative deviation (margin of error). +``` + +- Aggregate report for the `lookup` group that outputs the result to `console` and `CSV-file` + +```shell +./vendor/bin/phpbench run --report=aggregate --progress=dots --output=csv_file --output=console --group=lookup +``` + +>**Notice** +> +> Available groups: `construct` `lookup` `has` + +Generated MD-file example + +```text +> DI benchmark report +> =================== +> +>### suite: 1343b1d2654a3819c72a96d236302b70a504dac7, date: 2020-02-21, stime: 13:27:32 +> +>benchmark | subject | set | revs | its | mem_peak | best | mean | mode | worst | stdev | rstdev | diff +> --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- +>ContainerBench | benchSequentialLookups | 0 | 1000 | 5 | 1,454,024b | 168.945μs | 170.117μs | 169.782μs | 171.875μs | 0.957μs | 0.56% | 1.00x +>ContainerBench | benchSequentialLookups | 1 | 1000 | 5 | 1,445,296b | 3,347.656μs | 3,384.961μs | 3,390.411μs | 3,414.062μs | 21.823μs | 0.64% | 19.90x +>ContainerBench | benchSequentialLookups | 2 | 1000 | 5 | 1,445,568b | 3,420.898μs | 3,488.477μs | 3,447.260μs | 3,657.227μs | 85.705μs | 2.46% | 20.51x +>ContainerBench | benchRandomLookups | 0 | 1000 | 5 | 1,454,024b | 169.922μs | 171.875μs | 171.871μs | 173.828μs | 1.381μs | 0.80% | 1.01x +>ContainerBench | benchRandomLookups | 1 | 1000 | 5 | 1,445,296b | 3,353.515μs | 3,389.844μs | 3,377.299μs | 3,446.289μs | 31.598μs | 0.93% | 19.93x +>ContainerBench | benchRandomLookups | 2 | 1000 | 5 | 1,445,568b | 3,445.313μs | 3,587.696μs | 3,517.823μs | 3,749.023μs | 115.850μs | 3.23% | 21.09x +>ContainerBench | benchRandomLookupsComposite | 0 | 1000 | 5 | 1,454,032b | 297.852μs | 299.610μs | 298.855μs | 302.734μs | 1.680μs | 0.56% | 1.76x +>ContainerBench | benchRandomLookupsComposite | 1 | 1000 | 5 | 1,445,880b | 3,684.570μs | 3,708.984μs | 3,695.731μs | 3,762.695μs | 28.297μs | 0.76% | 21.80x +>ContainerBench | benchRandomLookupsComposite | 2 | 1000 | 5 | 1,446,152b | 3,668.946μs | 3,721.680μs | 3,727.407μs | 3,765.625μs | 30.881μs | 0.83% | 21.88x + +> **Legend** +> +> * benchmark: Benchmark class. +> * subject: Benchmark class method. +> * set: Set of data (provided by ParamProvider). +> * revs: Number of revolutions (represent the number of times that the code is executed). +> * its: Number of iterations (one measurement for each iteration). +> * mem_peak: (mean) Peak memory used by each iteration as retrieved by memory_get_peak_usage. +> * best: Maximum time of all iterations in variant. +> * mean: Mean time taken by all iterations in variant. +> * mode: Mode of all iterations in variant. +> * worst: Minimum time of all iterations in variant. +> * stdev: Standard deviation. +> * rstdev: The relative standard deviation. +> * diff: Difference between variants in a single group. +``` + ## Further reading - [Martin Fowler's article](https://martinfowler.com/articles/injection.html).