From 7fcd02018cf8adbbc56603a1d6c92cbf3da47016 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 14 Nov 2017 19:43:15 +0000 Subject: [PATCH] New DI containers added: yii2-di, unbox, joomla-di, di52, charnozem, DiMaria. Tests for zend-servicemanager, symfonydi, nette, league and aura updated to support newest versions. Some missing test6 instances added. And composer.json, test runners and README updated. --- DiMaria/test1.php | 18 +++ DiMaria/test2.php | 20 +++ DiMaria/test3.php | 20 +++ DiMaria/test4.php | 17 +++ DiMaria/test5.php | 19 +++ DiMaria/test6.php | 16 ++ DiMaria/test6a.php | 14 ++ README.md | 36 +++-- aura/test1.php | 6 +- aura/test2.php | 6 +- aura/test3.php | 6 +- aura/test4.php | 6 +- aura/test5.php | 8 +- aura/test6.php | 6 +- aura/test6a.php | 6 +- auryn/test6.php | 14 ++ auryn/test6a.php | 14 ++ chernozem/test1.php | 21 +++ chernozem/test2.php | 23 +++ chernozem/test3.php | 50 +++++++ chernozem/test4.php | 19 +++ chernozem/test5.php | 21 +++ chernozem/test6.php | 45 ++++++ chernozem/test6a.php | 45 ++++++ composer.json | 13 +- di52/test1.php | 19 +++ di52/test2.php | 23 +++ di52/test3.php | 24 +++ di52/test4.php | 25 ++++ di52/test5.php | 26 ++++ di52/test6.php | 15 ++ di52/test6a.php | 15 ++ joomla-di/test1.php | 19 +++ joomla-di/test2.php | 18 +++ joomla-di/test3.php | 20 +++ joomla-di/test4.php | 18 +++ joomla-di/test5.php | 19 +++ joomla-di/test6.php | 17 +++ joomla-di/test6a.php | 16 ++ league/test1.php | 5 +- league/test2.php | 6 +- league/test3.php | 6 +- league/test4.php | 10 +- league/test5.php | 11 +- league/test6.php | 7 +- league/test6a.php | 5 + nette/temp/Container_dcca481015.php | 121 +++++++++++++++ nette/temp/Container_dcca481015.php.lock | 0 nette/temp/Container_dcca481015.php.meta | 1 + nette/test1.php | 4 +- nette/test2.php | 15 +- nette/test3.php | 16 +- nette/test4.php | 12 +- nette/test5.php | 15 +- nette/test6.php | 13 +- nette/test6a.php | 17 +-- php-di/test6a.php | 27 ++++ slince-di/test1.php | 18 +++ slince-di/test2.php | 20 +++ slince-di/test3.php | 19 +++ slince-di/test4.php | 17 +++ slince-di/test5.php | 20 +++ slince-di/test6.php | 16 ++ slince-di/test6a.php | 15 ++ symfonydi/container_test1.php | 44 ++++-- symfonydi/container_test2.php | 70 +++++++++ symfonydi/container_test3.php | 178 +++++++++++++++++++++++ symfonydi/container_test4.php | 49 ++++--- symfonydi/container_test5.php | 58 +++++--- symfonydi/container_test6.php | 107 ++++++++------ symfonydi/test1.php | 2 +- symfonydi/test2.php | 4 +- symfonydi/test3.php | 4 +- symfonydi/test5.php | 5 +- symfonydi/test6.php | 2 +- symfonydi/test6a.php | 2 +- test1-5_results.html | 2 +- test1-5_runner.php | 2 +- test6_runner.php | 7 +- unbox/test1.php | 22 +++ unbox/test2.php | 23 +++ unbox/test3.php | 33 +++++ unbox/test4.php | 22 +++ unbox/test5.php | 23 +++ unbox/test6.php | 28 ++++ unbox/test6a.php | 28 ++++ yii2-di/test1.php | 19 +++ yii2-di/test2.php | 20 +++ yii2-di/test3.php | 20 +++ yii2-di/test4.php | 18 +++ yii2-di/test5.php | 19 +++ yii2-di/test6.php | 17 +++ yii2-di/test6a.php | 15 ++ zend-servicemanager/test1.php | 23 +-- zend-servicemanager/test2.php | 20 +-- zend-servicemanager/test3.php | 94 ++++-------- zend-servicemanager/test4.php | 20 +-- zend-servicemanager/test5.php | 31 ++-- zend-servicemanager/test6.php | 93 ++++-------- zend-servicemanager/test6a.php | 40 +++++ 100 files changed, 1895 insertions(+), 428 deletions(-) create mode 100644 DiMaria/test1.php create mode 100644 DiMaria/test2.php create mode 100644 DiMaria/test3.php create mode 100644 DiMaria/test4.php create mode 100644 DiMaria/test5.php create mode 100644 DiMaria/test6.php create mode 100644 DiMaria/test6a.php create mode 100644 auryn/test6.php create mode 100644 auryn/test6a.php create mode 100644 chernozem/test1.php create mode 100644 chernozem/test2.php create mode 100644 chernozem/test3.php create mode 100644 chernozem/test4.php create mode 100644 chernozem/test5.php create mode 100644 chernozem/test6.php create mode 100644 chernozem/test6a.php create mode 100644 di52/test1.php create mode 100644 di52/test2.php create mode 100644 di52/test3.php create mode 100644 di52/test4.php create mode 100644 di52/test5.php create mode 100644 di52/test6.php create mode 100644 di52/test6a.php create mode 100644 joomla-di/test1.php create mode 100644 joomla-di/test2.php create mode 100644 joomla-di/test3.php create mode 100644 joomla-di/test4.php create mode 100644 joomla-di/test5.php create mode 100644 joomla-di/test6.php create mode 100644 joomla-di/test6a.php create mode 100644 nette/temp/Container_dcca481015.php create mode 100644 nette/temp/Container_dcca481015.php.lock create mode 100644 nette/temp/Container_dcca481015.php.meta create mode 100644 php-di/test6a.php create mode 100644 slince-di/test1.php create mode 100644 slince-di/test2.php create mode 100644 slince-di/test3.php create mode 100644 slince-di/test4.php create mode 100644 slince-di/test5.php create mode 100644 slince-di/test6.php create mode 100644 slince-di/test6a.php create mode 100644 symfonydi/container_test2.php create mode 100644 symfonydi/container_test3.php create mode 100644 unbox/test1.php create mode 100644 unbox/test2.php create mode 100644 unbox/test3.php create mode 100644 unbox/test4.php create mode 100644 unbox/test5.php create mode 100644 unbox/test6.php create mode 100644 unbox/test6a.php create mode 100644 yii2-di/test1.php create mode 100644 yii2-di/test2.php create mode 100644 yii2-di/test3.php create mode 100644 yii2-di/test4.php create mode 100644 yii2-di/test5.php create mode 100644 yii2-di/test6.php create mode 100644 yii2-di/test6a.php create mode 100644 zend-servicemanager/test6a.php diff --git a/DiMaria/test1.php b/DiMaria/test1.php new file mode 100644 index 0000000..3a6836e --- /dev/null +++ b/DiMaria/test1.php @@ -0,0 +1,18 @@ +create('A'); +} + +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/DiMaria/test2.php b/DiMaria/test2.php new file mode 100644 index 0000000..dac58f3 --- /dev/null +++ b/DiMaria/test2.php @@ -0,0 +1,20 @@ +get('A'); +unset ($a); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $a = $di->create('A'); +} +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/DiMaria/test3.php b/DiMaria/test3.php new file mode 100644 index 0000000..5573362 --- /dev/null +++ b/DiMaria/test3.php @@ -0,0 +1,20 @@ +get('J'); +unset ($a); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $j = $di->create('J'); +} +$t2 = microtime(true); + +$results = [ +'time' => $t2 - $t1, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/DiMaria/test4.php b/DiMaria/test4.php new file mode 100644 index 0000000..06d87f1 --- /dev/null +++ b/DiMaria/test4.php @@ -0,0 +1,17 @@ +get('A'); +} +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/DiMaria/test5.php b/DiMaria/test5.php new file mode 100644 index 0000000..7d15b30 --- /dev/null +++ b/DiMaria/test5.php @@ -0,0 +1,19 @@ +setShared('A'); +$b = $di->create('B'); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $b = $di->create('B'); +} +$t2 = microtime(true); + +$results = [ +'time' => $t2 - $t1, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/DiMaria/test6.php b/DiMaria/test6.php new file mode 100644 index 0000000..b152e76 --- /dev/null +++ b/DiMaria/test6.php @@ -0,0 +1,16 @@ +create('J'); +} + + +$results = [ +'time' => 0, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); diff --git a/DiMaria/test6a.php b/DiMaria/test6a.php new file mode 100644 index 0000000..fb14ec4 --- /dev/null +++ b/DiMaria/test6a.php @@ -0,0 +1,14 @@ +create('J'); +} + +$results = [ +'time' => 0, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); diff --git a/README.md b/README.md index 31b2344..bd90681 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,27 @@ # DI Container Benchmarks Containers currently tested are: -- Aura -- Auryn -- Dice -- Laravel -- Leage -- Njasm -- Phalcon -- PHP-DI -- Pimple -- Symfony DI -- Zend\Di -- Zend\Servicemanager - - -**Nette is currently disabled due to not working as advertised. It fails to load Nette\DI\ContainerLoader which prevents any tests being done** +- [Aura.Di](ttps://github.com/auraphp/Aura.Di) +- [Auryn](https://github.com/rdlowrey/auryn) +- [Chernozem](https://github.com/pyrsmk/Chernozem) +- [Di52](https://github.com/lucatume/di52) +- [Dice](http://r.je/dice.html) +- [DiMaria](https://github.com/dangerousdan/dimaria) +- [Joomla DI](https://github.com/joomla-framework/di) +- [Laravel](https://github.com/illuminate/container) +- [Leage](https://github.com/thephpleague/container) +- [Nette](https://github.com/nette/di) +- [Njasm](https://github.com/njasm/container) +- [Phalcon](https://docs.phalconphp.com/en/3.2/di) +- [PHP-DI](http://php-di.org/) +- [Pimple](http://pimple.sensiolabs.org) +- [Slince DI](https://github.com/slince/di) +- [Symfony DI](https://github.com/symfony/dependency-injection) +- [Unbox](https://github.com/mindplay-dk/unbox) +- [Yii2-di](http://www.yiiframework.com/doc-2.0/guide-concept-di-container.html) +- [Zend\Di](https://github.com/zendframework/zend-di) +- [Zend\Servicemanager](https://github.com/zendframework/zend-servicemanager) + **Ray.Di does not seem to work without annotations. Requiring the classes to be coupled to the container goes against the spirit of DI and as such is not tested here** diff --git a/aura/test1.php b/aura/test1.php index 7f1d6c2..0c3ab8b 100644 --- a/aura/test1.php +++ b/aura/test1.php @@ -2,9 +2,9 @@ $t1 = microtime(true); -use Aura\Di\Container; -use Aura\Di\Factory; -$di = new Container(new Factory()); +use Aura\Di\ContainerBuilder; +$builder = new ContainerBuilder(); +$di = $builder->newInstance(); $di->set('A', $di->lazyNew('A')); for ($i = 0; $i < 10000; $i++) { diff --git a/aura/test2.php b/aura/test2.php index a93a7fc..9c3b7dd 100644 --- a/aura/test2.php +++ b/aura/test2.php @@ -1,9 +1,9 @@ newInstance(); $di->set('A', $di->lazyNew('A')); diff --git a/aura/test3.php b/aura/test3.php index ab72af0..a8f7d6e 100644 --- a/aura/test3.php +++ b/aura/test3.php @@ -1,9 +1,9 @@ newInstance(); $di->params['J'] = ['i' => $di->lazyNew('I')]; diff --git a/aura/test4.php b/aura/test4.php index 5f22361..ff38583 100644 --- a/aura/test4.php +++ b/aura/test4.php @@ -1,8 +1,8 @@ newInstance(); $di->set('A', $di->lazyNew('A')); diff --git a/aura/test5.php b/aura/test5.php index d0235e5..5ed3709 100644 --- a/aura/test5.php +++ b/aura/test5.php @@ -1,14 +1,14 @@ newInstance(); $di->set('A', $di->lazyNew('A')); +$di->params['B'] = ['a' => $di->lazyNew('A')]; $di->set('B', $di->lazyNew('B')); -$di->params['B'] = ['a' => $di->get('A')]; //Trigger the autoloader before measuring execution time $a = $di->newinstance('B'); diff --git a/aura/test6.php b/aura/test6.php index 81ae13c..16e4dce 100644 --- a/aura/test6.php +++ b/aura/test6.php @@ -1,8 +1,8 @@ newInstance(); $di->params['J'] = ['i' => $di->lazyNew('I')]; diff --git a/aura/test6a.php b/aura/test6a.php index 81ae13c..16e4dce 100644 --- a/aura/test6a.php +++ b/aura/test6a.php @@ -1,8 +1,8 @@ newInstance(); $di->params['J'] = ['i' => $di->lazyNew('I')]; diff --git a/auryn/test6.php b/auryn/test6.php new file mode 100644 index 0000000..420503c --- /dev/null +++ b/auryn/test6.php @@ -0,0 +1,14 @@ +make('J'); +} + +$results = [ + 'time' => 0, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/auryn/test6a.php b/auryn/test6a.php new file mode 100644 index 0000000..420503c --- /dev/null +++ b/auryn/test6a.php @@ -0,0 +1,14 @@ +make('J'); +} + +$results = [ + 'time' => 0, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/chernozem/test1.php b/chernozem/test1.php new file mode 100644 index 0000000..9487ee3 --- /dev/null +++ b/chernozem/test1.php @@ -0,0 +1,21 @@ +factory(function($chernozem) { + return new A(); +}); +for ($i = 0; $i < 10000; $i++) { + $a = $chernozem['A']; +} + +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/chernozem/test2.php b/chernozem/test2.php new file mode 100644 index 0000000..8fb281c --- /dev/null +++ b/chernozem/test2.php @@ -0,0 +1,23 @@ +factory(function($chernozem) { + return new A(); +}); +//trigger autoloader for all required files +$a = $chernozem['A']; +unset ($a); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $a = $chernozem['A']; +} +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/chernozem/test3.php b/chernozem/test3.php new file mode 100644 index 0000000..2d48237 --- /dev/null +++ b/chernozem/test3.php @@ -0,0 +1,50 @@ +factory(function($chernozem) { + return new A(); +}); +$chernozem['B'] = $chernozem->factory(function($chernozem) { + return new B($chernozem['A']); +}); +$chernozem['C'] = $chernozem->factory(function($chernozem) { + return new C($chernozem['B']); +}); +$chernozem['D'] = $chernozem->factory(function($chernozem) { + return new D($chernozem['C']); +}); +$chernozem['E'] = $chernozem->factory(function($chernozem) { + return new E($chernozem['D']); +}); +$chernozem['F'] = $chernozem->factory(function($chernozem) { + return new F($chernozem['E']); +}); +$chernozem['G'] = $chernozem->factory(function($chernozem) { + return new G($chernozem['F']); +}); +$chernozem['H'] = $chernozem->factory(function($chernozem) { + return new H($chernozem['G']); +}); +$chernozem['I'] = $chernozem->factory(function($chernozem) { + return new I($chernozem['H']); +}); +$chernozem['J'] = $chernozem->factory(function($chernozem) { + return new J($chernozem['I']); +}); +//trigger autoloader for all required files +$a = $chernozem['J']; +unset ($a); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $a = $chernozem['J']; +} +$t2 = microtime(true); + +$results = [ +'time' => $t2 - $t1, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/chernozem/test4.php b/chernozem/test4.php new file mode 100644 index 0000000..46580f9 --- /dev/null +++ b/chernozem/test4.php @@ -0,0 +1,19 @@ + $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/chernozem/test5.php b/chernozem/test5.php new file mode 100644 index 0000000..ddb9f37 --- /dev/null +++ b/chernozem/test5.php @@ -0,0 +1,21 @@ +factory(function($chernozem) { + return new B($chernozem['A']); +}); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $a = $chernozem['B']; +} +$t2 = microtime(true); + +$results = [ +'time' => $t2 - $t1, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/chernozem/test6.php b/chernozem/test6.php new file mode 100644 index 0000000..3336ba6 --- /dev/null +++ b/chernozem/test6.php @@ -0,0 +1,45 @@ +factory(function($chernozem) { + return new A(); +}); +$chernozem['B'] = $chernozem->factory(function($chernozem) { + return new B($chernozem['A']); +}); +$chernozem['C'] = $chernozem->factory(function($chernozem) { + return new C($chernozem['B']); +}); +$chernozem['D'] = $chernozem->factory(function($chernozem) { + return new D($chernozem['C']); +}); +$chernozem['E'] = $chernozem->factory(function($chernozem) { + return new E($chernozem['D']); +}); +$chernozem['F'] = $chernozem->factory(function($chernozem) { + return new F($chernozem['E']); +}); +$chernozem['G'] = $chernozem->factory(function($chernozem) { + return new G($chernozem['F']); +}); +$chernozem['H'] = $chernozem->factory(function($chernozem) { + return new H($chernozem['G']); +}); +$chernozem['I'] = $chernozem->factory(function($chernozem) { + return new I($chernozem['H']); +}); +$chernozem['J'] = $chernozem->factory(function($chernozem) { + return new J($chernozem['I']); +}); + +for ($i = 0; $i < 10000; $i++) { + $a = $chernozem['J']; +} + +$results = [ +'time' => 0, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/chernozem/test6a.php b/chernozem/test6a.php new file mode 100644 index 0000000..3336ba6 --- /dev/null +++ b/chernozem/test6a.php @@ -0,0 +1,45 @@ +factory(function($chernozem) { + return new A(); +}); +$chernozem['B'] = $chernozem->factory(function($chernozem) { + return new B($chernozem['A']); +}); +$chernozem['C'] = $chernozem->factory(function($chernozem) { + return new C($chernozem['B']); +}); +$chernozem['D'] = $chernozem->factory(function($chernozem) { + return new D($chernozem['C']); +}); +$chernozem['E'] = $chernozem->factory(function($chernozem) { + return new E($chernozem['D']); +}); +$chernozem['F'] = $chernozem->factory(function($chernozem) { + return new F($chernozem['E']); +}); +$chernozem['G'] = $chernozem->factory(function($chernozem) { + return new G($chernozem['F']); +}); +$chernozem['H'] = $chernozem->factory(function($chernozem) { + return new H($chernozem['G']); +}); +$chernozem['I'] = $chernozem->factory(function($chernozem) { + return new I($chernozem['H']); +}); +$chernozem['J'] = $chernozem->factory(function($chernozem) { + return new J($chernozem['I']); +}); + +for ($i = 0; $i < 10000; $i++) { + $a = $chernozem['J']; +} + +$results = [ +'time' => 0, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/composer.json b/composer.json index 623c538..6d2147b 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,15 @@ "symfony/config": "*", "symfony/proxy-manager-bridge": "*", "zendframework/zend-di": "*", - "zendframework/zend-servicemanager": "*" - } + "zendframework/zend-servicemanager": "*", + "dangerousdan/dimaria": "*", + "mindplay/unbox": "*", + "slince/di": "*", + "joomla/di": "*", + "yiisoft/yii2": "*", + "lucatume/di52": "*", + "pyrsmk/chernozem": "*" + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/di52/test1.php b/di52/test1.php new file mode 100644 index 0000000..0ac50ac --- /dev/null +++ b/di52/test1.php @@ -0,0 +1,19 @@ +make('A'); +} + +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/di52/test2.php b/di52/test2.php new file mode 100644 index 0000000..8d76e32 --- /dev/null +++ b/di52/test2.php @@ -0,0 +1,23 @@ +make('A'); +unset($a); + +$t1 = microtime(true); + +for ($i = 0; $i < 10000; $i++) { + $a = $di52->make('A'); +} + +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/di52/test3.php b/di52/test3.php new file mode 100644 index 0000000..f2572a9 --- /dev/null +++ b/di52/test3.php @@ -0,0 +1,24 @@ +make('J'); +unset($a); + + +$t1 = microtime(true); + +for ($i = 0; $i < 10000; $i++) { + $a = $di52->make('J'); +} + +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/di52/test4.php b/di52/test4.php new file mode 100644 index 0000000..adeac8f --- /dev/null +++ b/di52/test4.php @@ -0,0 +1,25 @@ +singleton('A', 'A'); + +//Trigger all autoloaders +$a = $di52->make('A'); +unset($a); + +$t1 = microtime(true); + +for ($i = 0; $i < 10000; $i++) { + $a = $di52->make('A'); +} + +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage() / 1024 / 1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/di52/test5.php b/di52/test5.php new file mode 100644 index 0000000..16e1bc9 --- /dev/null +++ b/di52/test5.php @@ -0,0 +1,26 @@ +singleton('A', 'A'); + +//Trigger all autoloaders +$b = $di52->make('B'); +unset($b); + + +$t1 = microtime(true); + +for ($i = 0; $i < 10000; $i++) { + $b = $di52->make('B'); +} + +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/di52/test6.php b/di52/test6.php new file mode 100644 index 0000000..92e296f --- /dev/null +++ b/di52/test6.php @@ -0,0 +1,15 @@ +make('J'); +} + +$results = [ + 'time' => 0, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage() / 1024 / 1024, +]; + +echo json_encode($results); \ No newline at end of file diff --git a/di52/test6a.php b/di52/test6a.php new file mode 100644 index 0000000..92e296f --- /dev/null +++ b/di52/test6a.php @@ -0,0 +1,15 @@ +make('J'); +} + +$results = [ + 'time' => 0, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage() / 1024 / 1024, +]; + +echo json_encode($results); \ No newline at end of file diff --git a/joomla-di/test1.php b/joomla-di/test1.php new file mode 100644 index 0000000..f622ca8 --- /dev/null +++ b/joomla-di/test1.php @@ -0,0 +1,19 @@ +buildObject('A', false); +for ($i = 0; $i < 10000; $i++) { + $a = $di->get('A', true); +} + +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/joomla-di/test2.php b/joomla-di/test2.php new file mode 100644 index 0000000..af5bfa7 --- /dev/null +++ b/joomla-di/test2.php @@ -0,0 +1,18 @@ +buildObject('A', false); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $a = $di->get('A', true); +} +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/joomla-di/test3.php b/joomla-di/test3.php new file mode 100644 index 0000000..9a8490a --- /dev/null +++ b/joomla-di/test3.php @@ -0,0 +1,20 @@ +buildObject('J', false); +$a = $di->get('J', true); +unset ($a); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $j = $di->get('J', true); +} +$t2 = microtime(true); + +$results = [ +'time' => $t2 - $t1, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/joomla-di/test4.php b/joomla-di/test4.php new file mode 100644 index 0000000..015d12b --- /dev/null +++ b/joomla-di/test4.php @@ -0,0 +1,18 @@ +buildObject('A', true); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $j = $di->get('A'); +} +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/joomla-di/test5.php b/joomla-di/test5.php new file mode 100644 index 0000000..c38f74f --- /dev/null +++ b/joomla-di/test5.php @@ -0,0 +1,19 @@ +buildObject('A', true); +$di->buildObject('B', false); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $b = $di->get('B', true); +} +$t2 = microtime(true); + +$results = [ +'time' => $t2 - $t1, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/joomla-di/test6.php b/joomla-di/test6.php new file mode 100644 index 0000000..32515b2 --- /dev/null +++ b/joomla-di/test6.php @@ -0,0 +1,17 @@ +buildObject('J', false); + +for ($i = 0; $i < $argv[1]; $i++) { + $j = $di->get('J', true); +} + + +$results = [ +'time' => 0, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); diff --git a/joomla-di/test6a.php b/joomla-di/test6a.php new file mode 100644 index 0000000..6e26f8a --- /dev/null +++ b/joomla-di/test6a.php @@ -0,0 +1,16 @@ +buildObject('J', false); + +for ($i = 0; $i < $argv[1]; $i++) { + $j = $di->get('J', true); +} + +$results = [ +'time' => 0, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); diff --git a/league/test1.php b/league/test1.php index ddb6e36..b0cfe37 100644 --- a/league/test1.php +++ b/league/test1.php @@ -1,14 +1,11 @@ share('A'); for ($i = 0; $i < 10000; $i++) { $a = $container->get('A'); } - $t2 = microtime(true); $results = [ diff --git a/league/test2.php b/league/test2.php index 047d1b3..cd7051c 100644 --- a/league/test2.php +++ b/league/test2.php @@ -1,19 +1,15 @@ share('A'); //trigger all autoloaders $a = $container->get('A'); unset($a); - - $t1 = microtime(true); - for ($i = 0; $i < 10000; $i++) { $a = $container->get('A'); } - $t2 = microtime(true); $results = [ diff --git a/league/test3.php b/league/test3.php index 17493de..92449aa 100644 --- a/league/test3.php +++ b/league/test3.php @@ -2,15 +2,17 @@ //Trigger all autoloaders $container = new League\Container\Container; +// register the reflection container as a delegate to enable auto wiring +$container->delegate( + new League\Container\ReflectionContainer +); $a = $container->get('J'); unset($a); $t1 = microtime(true); - for ($i = 0; $i < 10000; $i++) { $a = $container->get('J'); } - $t2 = microtime(true); $results = [ diff --git a/league/test4.php b/league/test4.php index fc4ef8a..3987a55 100644 --- a/league/test4.php +++ b/league/test4.php @@ -1,19 +1,19 @@ singleton('A'); - +// register the reflection container as a delegate to enable auto wiring +$container->delegate( + new League\Container\ReflectionContainer +); +$container->share('A'); //trigger all autoloaders $a = $container->get('A'); unset($a); $t1 = microtime(true); - - for ($i = 0; $i < 10000; $i++) { $a = $container->get('A'); } - $t2 = microtime(true); $results = [ diff --git a/league/test5.php b/league/test5.php index 5929f4a..feaf1cd 100644 --- a/league/test5.php +++ b/league/test5.php @@ -1,20 +1,19 @@ singleton('A'); - +// register the reflection container as a delegate to enable auto wiring +$container->delegate( + new League\Container\ReflectionContainer +); +$container->share('A'); //trigger all autoloaders $b = $container->get('B'); unset($b); $t1 = microtime(true); - - for ($i = 0; $i < 10000; $i++) { $a = $container->get('B'); } - $t2 = microtime(true); $results = [ diff --git a/league/test6.php b/league/test6.php index d39960a..8116292 100644 --- a/league/test6.php +++ b/league/test6.php @@ -1,8 +1,11 @@ delegate( + new League\Container\ReflectionContainer +); + for ($i = 0; $i < $argv[1]; $i++) { $j = $container->get('J'); } diff --git a/league/test6a.php b/league/test6a.php index eb098f7..8116292 100644 --- a/league/test6a.php +++ b/league/test6a.php @@ -1,6 +1,11 @@ delegate( + new League\Container\ReflectionContainer +); + for ($i = 0; $i < $argv[1]; $i++) { $j = $container->get('J'); } diff --git a/nette/temp/Container_dcca481015.php b/nette/temp/Container_dcca481015.php new file mode 100644 index 0000000..8dfb116 --- /dev/null +++ b/nette/temp/Container_dcca481015.php @@ -0,0 +1,121 @@ + [ + 'A' => [1 => ['a']], + 'B' => [1 => ['b']], + 'C' => [1 => ['c']], + 'D' => [1 => ['d']], + 'E' => [1 => ['e']], + 'F' => [1 => ['f']], + 'G' => [1 => ['g']], + 'H' => [1 => ['h']], + 'I' => [1 => ['i']], + 'J' => [1 => ['j']], + 'Nette\DI\Container' => [1 => ['container']], + ], + 'services' => [ + 'a' => 'A', + 'b' => 'B', + 'c' => 'C', + 'container' => 'Nette\DI\Container', + 'd' => 'D', + 'e' => 'E', + 'f' => 'F', + 'g' => 'G', + 'h' => 'H', + 'i' => 'I', + 'j' => 'J', + ], + 'aliases' => [], + ]; + + + public function __construct(array $params = []) + { + $this->parameters = $params; + $this->parameters += []; + } + + + public function createServiceA(): A + { + $service = new A; + return $service; + } + + + public function createServiceB(): B + { + $service = new B($this->createServiceA()); + return $service; + } + + + public function createServiceC(): C + { + $service = new C($this->createServiceB()); + return $service; + } + + + public function createServiceContainer(): Nette\DI\Container + { + return $this; + } + + + public function createServiceD(): D + { + $service = new D($this->createServiceC()); + return $service; + } + + + public function createServiceE(): E + { + $service = new E($this->createServiceD()); + return $service; + } + + + public function createServiceF(): F + { + $service = new F($this->createServiceE()); + return $service; + } + + + public function createServiceG(): G + { + $service = new G($this->createServiceF()); + return $service; + } + + + public function createServiceH(): H + { + $service = new H($this->createServiceG()); + return $service; + } + + + public function createServiceI(): I + { + $service = new I($this->createServiceH()); + return $service; + } + + + public function createServiceJ(): J + { + $service = new J($this->createServiceI()); + return $service; + } + + + public function initialize() + { + } +} diff --git a/nette/temp/Container_dcca481015.php.lock b/nette/temp/Container_dcca481015.php.lock new file mode 100644 index 0000000..e69de29 diff --git a/nette/temp/Container_dcca481015.php.meta b/nette/temp/Container_dcca481015.php.meta new file mode 100644 index 0000000..1a0dca9 --- /dev/null +++ b/nette/temp/Container_dcca481015.php.meta @@ -0,0 +1 @@ +a:6:{i:0;i:1;i:1;a:1:{s:78:"/var/www/public/php-dependency-injection-benchmarks/nette/config/services.neon";i:1510607617;}i:2;a:3:{s:67:"/var/www/public/php-dependency-injection-benchmarks/testclasses.php";i:1510607617;s:88:"/var/www/public/php-dependency-injection-benchmarks/vendor/nette/di/src/DI/Container.php";i:1504219320;s:96:"/var/www/public/php-dependency-injection-benchmarks/vendor/nette/utils/src/Utils/SmartObject.php";i:1503250349;}i:3;a:12:{i:0;s:1:"A";i:1;s:1:"B";i:2;s:1:"C";i:3;s:1:"D";i:4;s:1:"E";i:5;s:1:"F";i:6;s:1:"G";i:7;s:1:"H";i:8;s:1:"I";i:9;s:1:"J";i:10;s:18:"Nette\DI\Container";i:11;s:17:"Nette\SmartObject";}i:4;a:10:{i:0;s:14:"B::__construct";i:1;s:14:"C::__construct";i:2;s:14:"D::__construct";i:3;s:14:"E::__construct";i:4;s:14:"F::__construct";i:5;s:14:"G::__construct";i:6;s:14:"H::__construct";i:7;s:14:"I::__construct";i:8;s:14:"J::__construct";i:9;s:31:"Nette\DI\Container::__construct";}i:5;s:32:"dc1495edc5da2ada4eb7ec24c6768928";} \ No newline at end of file diff --git a/nette/test1.php b/nette/test1.php index 76b90cd..cd64cde 100644 --- a/nette/test1.php +++ b/nette/test1.php @@ -2,7 +2,7 @@ $t1 = microtime(true); $loader = new Nette\DI\ContainerLoader(__DIR__ . '/temp', TRUE); -$class = $loader->load('', function($compiler) { +$class = $loader->load(function($compiler) { $compiler->loadConfig(__DIR__ . '/config/services.neon'); }); $container = new $class; @@ -12,7 +12,7 @@ for ($i = 0; $i < 10000; $i++) { - $a = $container->createServiceA(); + $a = $container->createService('a'); } $t2 = microtime(true); diff --git a/nette/test2.php b/nette/test2.php index 8c132f8..a01408e 100644 --- a/nette/test2.php +++ b/nette/test2.php @@ -1,19 +1,18 @@ setTempDirectory(__DIR__ . '/temp'); -$configurator->defaultExtensions = array(); -$configurator->addConfig(__DIR__ . '/config/services.neon'); -$container = $configurator->createContainer(); // compile - +$loader = new Nette\DI\ContainerLoader(__DIR__ . '/temp'); +$class = $loader->load(function($compiler) { + $compiler->loadConfig(__DIR__ . '/config/services.neon'); +}); +$container = new $class; //Trigger the autoloader -$a = $container->createServiceA(); +$a = $container->createService('a'); unset($a); $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { - $a = $container->createServiceA(); + $a = $container->createService('a'); } $t2 = microtime(true); diff --git a/nette/test3.php b/nette/test3.php index 4eb493e..290a539 100644 --- a/nette/test3.php +++ b/nette/test3.php @@ -1,21 +1,19 @@ setTempDirectory(__DIR__ . '/temp'); -$configurator->defaultExtensions = array(); -$configurator->addConfig(__DIR__ . '/config/services.neon'); -$container = $configurator->createContainer(); // compile +$loader = new Nette\DI\ContainerLoader(__DIR__ . '/temp'); +$class = $loader->load(function($compiler) { + $compiler->loadConfig(__DIR__ . '/config/services.neon'); +}); +$container = new $class; - -//Trigger autoloader -$j = $container->createServiceJ('j'); +$j = $container->createService('j'); unset($j); $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { - $j = $container->createServiceJ(); + $j = $container->createService('j'); } $t2 = microtime(true); diff --git a/nette/test4.php b/nette/test4.php index a800cec..b681c02 100644 --- a/nette/test4.php +++ b/nette/test4.php @@ -1,12 +1,12 @@ setTempDirectory(__DIR__ . '/temp'); -$configurator->defaultExtensions = array(); -$configurator->addConfig(__DIR__ . '/config/services.neon'); -$container = $configurator->createContainer(); // compile +$loader = new Nette\DI\ContainerLoader(__DIR__ . '/temp'); +$class = $loader->load(function($compiler) { + $compiler->loadConfig(__DIR__ . '/config/services.neon'); +}); +$container = new $class; + -//Trigger autoloader $a = $container->getService('a'); unset($a); diff --git a/nette/test5.php b/nette/test5.php index 30e0eb1..577beff 100644 --- a/nette/test5.php +++ b/nette/test5.php @@ -1,21 +1,20 @@ setTempDirectory(__DIR__ . '/temp'); -$configurator->defaultExtensions = array(); -$configurator->addConfig(__DIR__ . '/config/services.neon'); -$container = $configurator->createContainer(); // compile - +$loader = new Nette\DI\ContainerLoader(__DIR__ . '/temp'); +$class = $loader->load(function($compiler) { + $compiler->loadConfig(__DIR__ . '/config/services.neon'); +}); +$container = new $class; //trigger autoloader -$a = $container->getService('b'); +$a = $container->getService('a'); unset($a); $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { - $a = $container->getService('b'); + $a = $container->createService('b'); } $t2 = microtime(true); diff --git a/nette/test6.php b/nette/test6.php index 9d542de..aab53a2 100644 --- a/nette/test6.php +++ b/nette/test6.php @@ -1,15 +1,14 @@ setTempDirectory(__DIR__ . '/temp'); -$configurator->defaultExtensions = array(); -$configurator->addConfig(__DIR__ . '/config/services.neon'); -$container = $configurator->createContainer(); // compile +$loader = new Nette\DI\ContainerLoader(__DIR__ . '/temp'); +$class = $loader->load(function($compiler) { + $compiler->loadConfig(__DIR__ . '/config/services.neon'); +}); +$container = new $class; for ($i = 0; $i < $argv[1]; $i++) { - $j = $container->createServiceJ(); + $j = $container->createService('j'); } $results = [ diff --git a/nette/test6a.php b/nette/test6a.php index 171ce74..aab53a2 100644 --- a/nette/test6a.php +++ b/nette/test6a.php @@ -1,19 +1,14 @@ setTempDirectory(__DIR__ . '/temp'); -$configurator->defaultExtensions = array(); -$configurator->addConfig(__DIR__ . '/config/services.neon'); -$container = $configurator->createContainer(); // compile +$loader = new Nette\DI\ContainerLoader(__DIR__ . '/temp'); +$class = $loader->load(function($compiler) { + $compiler->loadConfig(__DIR__ . '/config/services.neon'); +}); +$container = new $class; for ($i = 0; $i < $argv[1]; $i++) { - $j = $container->createServiceJ(); + $j = $container->createService('j'); } $results = [ diff --git a/php-di/test6a.php b/php-di/test6a.php new file mode 100644 index 0000000..0ee6466 --- /dev/null +++ b/php-di/test6a.php @@ -0,0 +1,27 @@ +addDefinitions(__DIR__ . '/config-test3.php'); +$builder->setDefinitionCache(new \Doctrine\Common\Cache\ArrayCache()); + +$container = $builder->build(); + +//trigger autoloader +$j = $container->get('J'); +unset ($j); + +$t1 = microtime(true); + +for ($i = 0; $i < 10000; $i++) { + $j = $container->get('J'); + +} + +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); diff --git a/slince-di/test1.php b/slince-di/test1.php new file mode 100644 index 0000000..a497adf --- /dev/null +++ b/slince-di/test1.php @@ -0,0 +1,18 @@ +get('A'); +} + +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/slince-di/test2.php b/slince-di/test2.php new file mode 100644 index 0000000..3639d9f --- /dev/null +++ b/slince-di/test2.php @@ -0,0 +1,20 @@ +get('A'); +unset ($a); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $a = $di->get('A'); +} +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/slince-di/test3.php b/slince-di/test3.php new file mode 100644 index 0000000..36b9a22 --- /dev/null +++ b/slince-di/test3.php @@ -0,0 +1,19 @@ +get('J'); +unset ($a); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $j = $di->get('J'); +} +$t2 = microtime(true); + +$results = [ +'time' => $t2 - $t1, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/slince-di/test4.php b/slince-di/test4.php new file mode 100644 index 0000000..583575d --- /dev/null +++ b/slince-di/test4.php @@ -0,0 +1,17 @@ +get('A'); +} +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/slince-di/test5.php b/slince-di/test5.php new file mode 100644 index 0000000..0057453 --- /dev/null +++ b/slince-di/test5.php @@ -0,0 +1,20 @@ +define('A', 'A'); +$di->share('A'); +$b = $di->get('B'); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $b = $di->get('B'); +} +$t2 = microtime(true); + +$results = [ +'time' => $t2 - $t1, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/slince-di/test6.php b/slince-di/test6.php new file mode 100644 index 0000000..aea8378 --- /dev/null +++ b/slince-di/test6.php @@ -0,0 +1,16 @@ +get('J'); +} + + +$results = [ +'time' => 0, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); diff --git a/slince-di/test6a.php b/slince-di/test6a.php new file mode 100644 index 0000000..203558a --- /dev/null +++ b/slince-di/test6a.php @@ -0,0 +1,15 @@ +get('J'); +} + +$results = [ +'time' => 0, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); diff --git a/symfonydi/container_test1.php b/symfonydi/container_test1.php index b1ab7e8..f0a987d 100644 --- a/symfonydi/container_test1.php +++ b/symfonydi/container_test1.php @@ -1,36 +1,32 @@ services = - $this->scopedServices = - $this->scopeStacks = array(); - $this->scopes = array(); - $this->scopeChildren = array(); + $this->services = array(); + $this->normalizedIds = array( + 'a' => 'A', + ); $this->methodMap = array( - 'a' => 'getAService', + 'A' => 'getAService', ); $this->aliases = array(); @@ -41,13 +37,31 @@ public function __construct() */ public function compile() { - throw new LogicException('You cannot compile a dumped frozen container.'); + throw new LogicException('You cannot compile a dumped container that was already compiled.'); + } + + /** + * {@inheritdoc} + */ + public function isCompiled() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function isFrozen() + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED); + + return true; } /** - * Gets the 'a' service. + * Gets the public 'A' service. * - * @return \A A A instance. + * @return \A */ protected function getAService() { diff --git a/symfonydi/container_test2.php b/symfonydi/container_test2.php new file mode 100644 index 0000000..f0a987d --- /dev/null +++ b/symfonydi/container_test2.php @@ -0,0 +1,70 @@ +services = array(); + $this->normalizedIds = array( + 'a' => 'A', + ); + $this->methodMap = array( + 'A' => 'getAService', + ); + + $this->aliases = array(); + } + + /** + * {@inheritdoc} + */ + public function compile() + { + throw new LogicException('You cannot compile a dumped container that was already compiled.'); + } + + /** + * {@inheritdoc} + */ + public function isCompiled() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function isFrozen() + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED); + + return true; + } + + /** + * Gets the public 'A' service. + * + * @return \A + */ + protected function getAService() + { + return new \A(); + } +} diff --git a/symfonydi/container_test3.php b/symfonydi/container_test3.php new file mode 100644 index 0000000..9912868 --- /dev/null +++ b/symfonydi/container_test3.php @@ -0,0 +1,178 @@ +services = array(); + $this->normalizedIds = array( + 'a' => 'A', + 'b' => 'B', + 'c' => 'C', + 'd' => 'D', + 'e' => 'E', + 'f' => 'F', + 'g' => 'G', + 'h' => 'H', + 'i' => 'I', + 'j' => 'J', + ); + $this->methodMap = array( + 'A' => 'getAService', + 'B' => 'getBService', + 'C' => 'getCService', + 'D' => 'getDService', + 'E' => 'getEService', + 'F' => 'getFService', + 'G' => 'getGService', + 'H' => 'getHService', + 'I' => 'getIService', + 'J' => 'getJService', + ); + + $this->aliases = array(); + } + + /** + * {@inheritdoc} + */ + public function compile() + { + throw new LogicException('You cannot compile a dumped container that was already compiled.'); + } + + /** + * {@inheritdoc} + */ + public function isCompiled() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function isFrozen() + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED); + + return true; + } + + /** + * Gets the public 'A' service. + * + * @return \A + */ + protected function getAService() + { + return new \A(); + } + + /** + * Gets the public 'B' service. + * + * @return \B + */ + protected function getBService() + { + return new \B(new \A()); + } + + /** + * Gets the public 'C' service. + * + * @return \C + */ + protected function getCService() + { + return new \C(new \B(new \A())); + } + + /** + * Gets the public 'D' service. + * + * @return \D + */ + protected function getDService() + { + return new \D(new \C(new \B(new \A()))); + } + + /** + * Gets the public 'E' service. + * + * @return \E + */ + protected function getEService() + { + return new \E(new \D(new \C(new \B(new \A())))); + } + + /** + * Gets the public 'F' service. + * + * @return \F + */ + protected function getFService() + { + return new \F(new \E(new \D(new \C(new \B(new \A()))))); + } + + /** + * Gets the public 'G' service. + * + * @return \G + */ + protected function getGService() + { + return new \G(new \F(new \E(new \D(new \C(new \B(new \A())))))); + } + + /** + * Gets the public 'H' service. + * + * @return \H + */ + protected function getHService() + { + return new \H(new \G(new \F(new \E(new \D(new \C(new \B(new \A()))))))); + } + + /** + * Gets the public 'I' service. + * + * @return \I + */ + protected function getIService() + { + return new \I(new \H(new \G(new \F(new \E(new \D(new \C(new \B(new \A())))))))); + } + + /** + * Gets the public 'J' service. + * + * @return \J + */ + protected function getJService() + { + return new \J(new \I(new \H(new \G(new \F(new \E(new \D(new \C(new \B(new \A()))))))))); + } +} diff --git a/symfonydi/container_test4.php b/symfonydi/container_test4.php index 59f5fae..857d7a6 100644 --- a/symfonydi/container_test4.php +++ b/symfonydi/container_test4.php @@ -1,36 +1,32 @@ services = - $this->scopedServices = - $this->scopeStacks = array(); - $this->scopes = array(); - $this->scopeChildren = array(); + $this->services = array(); + $this->normalizedIds = array( + 'a' => 'A', + ); $this->methodMap = array( - 'a' => 'getAService', + 'A' => 'getAService', ); $this->aliases = array(); @@ -41,19 +37,34 @@ public function __construct() */ public function compile() { - throw new LogicException('You cannot compile a dumped frozen container.'); + throw new LogicException('You cannot compile a dumped container that was already compiled.'); } /** - * Gets the 'a' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * {@inheritdoc} + */ + public function isCompiled() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function isFrozen() + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED); + + return true; + } + + /** + * Gets the public 'A' shared service. * - * @return \A A A instance. + * @return \A */ protected function getAService() { - return $this->services['a'] = new \A(); + return $this->services['A'] = new \A(); } } diff --git a/symfonydi/container_test5.php b/symfonydi/container_test5.php index 972aa1f..40df73e 100644 --- a/symfonydi/container_test5.php +++ b/symfonydi/container_test5.php @@ -1,37 +1,34 @@ services = - $this->scopedServices = - $this->scopeStacks = array(); - $this->scopes = array(); - $this->scopeChildren = array(); + $this->services = array(); + $this->normalizedIds = array( + 'a' => 'A', + 'b' => 'B', + ); $this->methodMap = array( - 'a' => 'getAService', - 'b' => 'getBService', + 'A' => 'getAService', + 'B' => 'getBService', ); $this->aliases = array(); @@ -42,29 +39,44 @@ public function __construct() */ public function compile() { - throw new LogicException('You cannot compile a dumped frozen container.'); + throw new LogicException('You cannot compile a dumped container that was already compiled.'); } /** - * Gets the 'a' service. - * - * This service is shared. - * This method always returns the same instance of the service. + * {@inheritdoc} + */ + public function isCompiled() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function isFrozen() + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED); + + return true; + } + + /** + * Gets the public 'A' shared service. * - * @return \A A A instance. + * @return \A */ protected function getAService() { - return $this->services['a'] = new \A(); + return $this->services['A'] = new \A(); } /** - * Gets the 'b' service. + * Gets the public 'B' service. * - * @return \B A B instance. + * @return \B */ protected function getBService() { - return new \B($this->get('a')); + return new \B(${($_ = isset($this->services['A']) ? $this->services['A'] : $this->get('A')) && false ?: '_'}); } } diff --git a/symfonydi/container_test6.php b/symfonydi/container_test6.php index a6796bb..9912868 100644 --- a/symfonydi/container_test6.php +++ b/symfonydi/container_test6.php @@ -1,45 +1,50 @@ services = - $this->scopedServices = - $this->scopeStacks = array(); - $this->scopes = array(); - $this->scopeChildren = array(); + $this->services = array(); + $this->normalizedIds = array( + 'a' => 'A', + 'b' => 'B', + 'c' => 'C', + 'd' => 'D', + 'e' => 'E', + 'f' => 'F', + 'g' => 'G', + 'h' => 'H', + 'i' => 'I', + 'j' => 'J', + ); $this->methodMap = array( - 'a' => 'getAService', - 'b' => 'getBService', - 'c' => 'getCService', - 'd' => 'getDService', - 'e' => 'getEService', - 'f' => 'getFService', - 'g' => 'getGService', - 'h' => 'getHService', - 'i' => 'getIService', - 'j' => 'getJService', + 'A' => 'getAService', + 'B' => 'getBService', + 'C' => 'getCService', + 'D' => 'getDService', + 'E' => 'getEService', + 'F' => 'getFService', + 'G' => 'getGService', + 'H' => 'getHService', + 'I' => 'getIService', + 'J' => 'getJService', ); $this->aliases = array(); @@ -50,13 +55,31 @@ public function __construct() */ public function compile() { - throw new LogicException('You cannot compile a dumped frozen container.'); + throw new LogicException('You cannot compile a dumped container that was already compiled.'); + } + + /** + * {@inheritdoc} + */ + public function isCompiled() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function isFrozen() + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED); + + return true; } /** - * Gets the 'a' service. + * Gets the public 'A' service. * - * @return \A A A instance. + * @return \A */ protected function getAService() { @@ -64,9 +87,9 @@ protected function getAService() } /** - * Gets the 'b' service. + * Gets the public 'B' service. * - * @return \B A B instance. + * @return \B */ protected function getBService() { @@ -74,9 +97,9 @@ protected function getBService() } /** - * Gets the 'c' service. + * Gets the public 'C' service. * - * @return \C A C instance. + * @return \C */ protected function getCService() { @@ -84,9 +107,9 @@ protected function getCService() } /** - * Gets the 'd' service. + * Gets the public 'D' service. * - * @return \D A D instance. + * @return \D */ protected function getDService() { @@ -94,9 +117,9 @@ protected function getDService() } /** - * Gets the 'e' service. + * Gets the public 'E' service. * - * @return \E A E instance. + * @return \E */ protected function getEService() { @@ -104,9 +127,9 @@ protected function getEService() } /** - * Gets the 'f' service. + * Gets the public 'F' service. * - * @return \F A F instance. + * @return \F */ protected function getFService() { @@ -114,9 +137,9 @@ protected function getFService() } /** - * Gets the 'g' service. + * Gets the public 'G' service. * - * @return \G A G instance. + * @return \G */ protected function getGService() { @@ -124,9 +147,9 @@ protected function getGService() } /** - * Gets the 'h' service. + * Gets the public 'H' service. * - * @return \H A H instance. + * @return \H */ protected function getHService() { @@ -134,9 +157,9 @@ protected function getHService() } /** - * Gets the 'i' service. + * Gets the public 'I' service. * - * @return \I A I instance. + * @return \I */ protected function getIService() { @@ -144,9 +167,9 @@ protected function getIService() } /** - * Gets the 'j' service. + * Gets the public 'J' service. * - * @return \J A J instance. + * @return \J */ protected function getJService() { diff --git a/symfonydi/test1.php b/symfonydi/test1.php index 6c43b4f..6dafbde 100644 --- a/symfonydi/test1.php +++ b/symfonydi/test1.php @@ -12,7 +12,7 @@ $definition = new Symfony\Component\DependencyInjection\Definition('A', []); - $definition->setScope('prototype'); + $definition->setShared(false); $container->setDefinition('A', $definition); $container->compile(); diff --git a/symfonydi/test2.php b/symfonydi/test2.php index 4251067..3d1af12 100644 --- a/symfonydi/test2.php +++ b/symfonydi/test2.php @@ -1,6 +1,6 @@ setScope('prototype'); + $definition->setShared(false); $container->setDefinition('A', $definition); $container->compile(); diff --git a/symfonydi/test3.php b/symfonydi/test3.php index df9a18c..ba212e6 100644 --- a/symfonydi/test3.php +++ b/symfonydi/test3.php @@ -1,6 +1,6 @@ setScope('prototype'); + $definition->setShared(false); $container->setDefinition($classes[$i], $definition); } diff --git a/symfonydi/test5.php b/symfonydi/test5.php index ee80336..cb4aa22 100644 --- a/symfonydi/test5.php +++ b/symfonydi/test5.php @@ -9,10 +9,11 @@ $container = new Symfony\Component\DependencyInjection\ContainerBuilder; - $container->register('A', 'A'); + $definition = new Symfony\Component\DependencyInjection\Definition('A', []); + $container->setDefinition('A', $definition); $ref = [new Symfony\Component\DependencyInjection\Reference('A')]; $definition = new Symfony\Component\DependencyInjection\Definition('B', $ref ); - $definition->setScope('prototype'); + $definition->setShared(false); $container->setDefinition('B', $definition); diff --git a/symfonydi/test6.php b/symfonydi/test6.php index cfa0116..5992444 100644 --- a/symfonydi/test6.php +++ b/symfonydi/test6.php @@ -18,7 +18,7 @@ else $ref = []; $definition = new Symfony\Component\DependencyInjection\Definition($classes[$i], $ref ); - $definition->setScope('prototype'); + $definition->setShared(false); $container->setDefinition($classes[$i], $definition); } diff --git a/symfonydi/test6a.php b/symfonydi/test6a.php index 998dbe5..6b912ab 100644 --- a/symfonydi/test6a.php +++ b/symfonydi/test6a.php @@ -17,7 +17,7 @@ else $ref = []; $definition = new Symfony\Component\DependencyInjection\Definition($classes[$i], $ref ); - $definition->setScope('prototype'); + $definition->setShared(false); $container->setDefinition($classes[$i], $definition); } diff --git a/test1-5_results.html b/test1-5_results.html index 7b824f8..c0138ee 100644 --- a/test1-5_results.html +++ b/test1-5_results.html @@ -1 +1 @@ -

Test 1 - Create single object (incl autoload time)

ContainerTimeMemoryFiles
dice0.02560.430512
phalcon0.05780.26292
symfonydi0.07190.486815
njasm0.08110.437419
pimple0.08740.418712
league0.11550.482122
auryn0.18540.544617
aura0.21040.471618
laravel0.23960.549913
zend-servicemanager0.27970.62516
php-di0.37230.593743
zend-di0.67480.748635

Test 2 - Create single object (excl autoload time)

ContainerTimeMemoryFiles
dice0.0250.430412
phalcon0.05840.26292
symfonydi0.06790.486815
njasm0.08060.436619
pimple0.08750.418912
league0.1130.481922
auryn0.18290.544717
aura0.20910.471318
laravel0.23820.549913
zend-servicemanager0.28210.624916
php-di0.36060.594743
zend-di0.64560.747935

Test 3 - Create deep object graph

ContainerTimeMemoryFiles
symfonydi0.15370.490815
dice0.53770.430412
phalcon0.69860.29572
pimple0.89530.423512
njasm1.49540.43719
league1.53640.481922
aura2.34380.471818
zend-servicemanager2.68880.629216
auryn3.11950.544717
laravel3.25130.550313
php-di4.98630.609647
zend-di22.66180.748236

Test 4 - Fetch the same instance (service) from the container repeatedly

ContainerTimeMemoryFiles
phalcon0.00830.26292
pimple0.01140.418512
dice0.01180.430612
njasm0.01250.436619
aura0.01660.471418
laravel0.01960.550113
php-di0.02070.563438
league0.02690.481922
zend-servicemanager0.0340.624916
symfonydi0.04080.486815
auryn0.05590.544817
zend-di0.19640.748235

Test 5 - Inject a service into a new object repeatedly

ContainerTimeMemoryFiles
dice0.07170.430612
phalcon0.07990.26572
symfonydi0.09550.487715
pimple0.1070.419512
njasm0.17510.436619
league0.19480.482222
aura0.23470.471918
zend-servicemanager0.32380.625216
laravel0.38950.550113
auryn0.40980.544817
php-di0.5860.607647
zend-di1.50920.748836
\ No newline at end of file +

Test 1 - Create single object (incl autoload time)

ContainerTimeMemoryFiles
dice0.00930.535310
joomla-di0.01330.535310
phalcon0.01660.53539
di520.01760.561310
pimple0.02230.535310
DiMaria0.0280.535312
symfonydi0.02940.558914
yii2-di0.03020.553713
chernozem0.03450.535313
unbox0.0360.535316
nette0.04910.544914
zend-servicemanager0.05590.581416
auryn0.05690.58215
laravel0.05770.585912
njasm0.05840.569418
slince-di0.06560.569117
aura0.06760.563319
league0.10080.570630
php-di0.22640.672544
zend-di0.22780.712834

Test 2 - Create single object (excl autoload time)

ContainerTimeMemoryFiles
dice0.00340.535310
league0.00440.570630
joomla-di0.00590.535310
di520.00660.561310
symfonydi0.00690.558914
DiMaria0.00750.535312
unbox0.00760.535316
yii2-di0.00770.553813
njasm0.010.569418
chernozem0.01040.535313
pimple0.01360.535310
zend-servicemanager0.01570.581416
aura0.01630.563319
phalcon0.01650.53539
nette0.02030.544913
slince-di0.02220.569217
auryn0.02770.58215
laravel0.03750.585912
php-di0.04130.672644
zend-di0.09680.712834

Test 3 - Create deep object graph

ContainerTimeMemoryFiles
joomla-di0.00810.535310
symfonydi0.02090.559214
unbox0.03310.535316
nette0.04220.544913
dice0.09090.535310
yii2-di0.10820.580214
chernozem0.11290.535313
DiMaria0.13390.535312
pimple0.1510.535310
phalcon0.18920.53539
aura0.20230.563519
njasm0.22550.569818
di520.34714.899410
slince-di0.4650.569217
zend-servicemanager0.46760.581616
auryn0.520.58215
laravel0.57930.585912
php-di0.6960.676349
league1.87510.686132
zend-di4.47770.713235

Test 4 - Fetch the same instance (service) from the container repeatedly

ContainerTimeMemoryFiles
nette0.00040.544913
di520.00080.561310
njasm0.00080.569418
aura0.00090.563319
zend-servicemanager0.0010.581416
DiMaria0.00110.535312
dice0.00130.535310
phalcon0.00160.53539
pimple0.00190.535310
php-di0.00190.640239
joomla-di0.00270.535310
symfonydi0.00280.558914
league0.00450.570131
unbox0.00470.535316
auryn0.00660.582115
laravel0.00660.585912
chernozem0.00730.535313
yii2-di0.00830.553713
zend-di0.02840.712834
slince-di0.03070.569117

Test 5 - Inject a service into a new object repeatedly

ContainerTimeMemoryFiles
joomla-di0.00830.535310
symfonydi0.00950.558914
dice0.01110.535310
DiMaria0.01770.535312
yii2-di0.01770.581614
pimple0.01830.535310
chernozem0.01950.535313
nette0.02460.544913
phalcon0.02470.53539
njasm0.02820.569418
di520.03270.858510
unbox0.03840.535316
aura0.03910.563319
slince-di0.0540.569317
zend-servicemanager0.05430.581416
auryn0.06950.582115
laravel0.07650.585912
php-di0.0830.674749
league0.09920.570136
zend-di0.24160.713235
\ No newline at end of file diff --git a/test1-5_runner.php b/test1-5_runner.php index 8380662..eafd00a 100644 --- a/test1-5_runner.php +++ b/test1-5_runner.php @@ -21,7 +21,7 @@ function cliPrint($text, $newLine = true) { cliPrint('Running each test ' . $runs . ' times'); //Containers to be tested (dir names) -$containers = ['aura', 'auryn', 'dice', 'laravel', 'league', 'njasm', 'phalcon', 'php-di', 'pimple', 'symfonydi', 'zend-di', 'zend-servicemanager']; +$containers = ['aura', 'auryn', 'chernozem', 'di52', 'dice', 'DiMaria', 'joomla-di', 'laravel', 'league', 'nette', 'njasm', 'phalcon', 'php-di', 'pimple', 'slince-di', 'symfonydi', 'unbox', 'yii2-di', 'zend-di', 'zend-servicemanager']; //Default ini file to use for tests diff --git a/test6_runner.php b/test6_runner.php index 201356c..7c28af6 100644 --- a/test6_runner.php +++ b/test6_runner.php @@ -1,4 +1,5 @@ '; } - +$ta2 = microtime(true); +echo $ta2 - $ta1; if (!$isCli) echo $html; else file_put_contents('test6_results.html', $html); \ No newline at end of file diff --git a/unbox/test1.php b/unbox/test1.php new file mode 100644 index 0000000..b132e4d --- /dev/null +++ b/unbox/test1.php @@ -0,0 +1,22 @@ +register("A"); + +$di = $factory->createContainer(); +for ($i = 0; $i < 10000; $i++) { + $a = $di->get('A'); +} + +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/unbox/test2.php b/unbox/test2.php new file mode 100644 index 0000000..5a74e64 --- /dev/null +++ b/unbox/test2.php @@ -0,0 +1,23 @@ +register("A"); + +$di = $factory->createContainer(); +$a = $di->get('A'); +unset ($a); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $a = $di->create('A'); +} +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/unbox/test3.php b/unbox/test3.php new file mode 100644 index 0000000..82ee4d4 --- /dev/null +++ b/unbox/test3.php @@ -0,0 +1,33 @@ +register("A"); +$factory->register("B"); +$factory->register("C"); +$factory->register("D"); +$factory->register("E"); +$factory->register("F"); +$factory->register("G"); +$factory->register("H"); +$factory->register("I"); +$factory->register("J"); + +$di = $factory->createContainer(); +$a = $di->get('J'); +unset ($a); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $j = $di->create('J'); +} +$t2 = microtime(true); + +$results = [ +'time' => $t2 - $t1, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/unbox/test4.php b/unbox/test4.php new file mode 100644 index 0000000..38e453e --- /dev/null +++ b/unbox/test4.php @@ -0,0 +1,22 @@ +register("A"); + +$di = $factory->createContainer(); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $j = $di->get('A'); +} +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/unbox/test5.php b/unbox/test5.php new file mode 100644 index 0000000..b26d494 --- /dev/null +++ b/unbox/test5.php @@ -0,0 +1,23 @@ +register("A"); +$factory->register("B"); + +$di = $factory->createContainer(); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $b = $di->create('B'); +} +$t2 = microtime(true); + +$results = [ +'time' => $t2 - $t1, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/unbox/test6.php b/unbox/test6.php new file mode 100644 index 0000000..00830c7 --- /dev/null +++ b/unbox/test6.php @@ -0,0 +1,28 @@ +register("A"); +$factory->register("B"); +$factory->register("C"); +$factory->register("D"); +$factory->register("E"); +$factory->register("F"); +$factory->register("G"); +$factory->register("H"); +$factory->register("I"); +$factory->register("J"); +$di = $factory->createContainer(); + +for ($i = 0; $i < $argv[1]; $i++) { + $j = $di->create('J'); +} + +$results = [ +'time' => 0, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); diff --git a/unbox/test6a.php b/unbox/test6a.php new file mode 100644 index 0000000..8c07d33 --- /dev/null +++ b/unbox/test6a.php @@ -0,0 +1,28 @@ +register("A"); +$factory->register("B"); +$factory->register("C"); +$factory->register("D"); +$factory->register("E"); +$factory->register("F"); +$factory->register("G"); +$factory->register("H"); +$factory->register("I"); +$factory->register("J"); + +$di = $factory->createContainer(); +for ($i = 0; $i < $argv[1]; $i++) { + $j = $di->create('J'); +} + +$results = [ +'time' => 0, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); diff --git a/yii2-di/test1.php b/yii2-di/test1.php new file mode 100644 index 0000000..c6b63ee --- /dev/null +++ b/yii2-di/test1.php @@ -0,0 +1,19 @@ +get('A'); +} + +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/yii2-di/test2.php b/yii2-di/test2.php new file mode 100644 index 0000000..db9f180 --- /dev/null +++ b/yii2-di/test2.php @@ -0,0 +1,20 @@ +get('A'); +unset ($a); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $a = $di->get('A'); +} +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/yii2-di/test3.php b/yii2-di/test3.php new file mode 100644 index 0000000..3807ea0 --- /dev/null +++ b/yii2-di/test3.php @@ -0,0 +1,20 @@ +get('J'); +unset ($a); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $j = $di->get('J'); +} +$t2 = microtime(true); + +$results = [ +'time' => $t2 - $t1, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/yii2-di/test4.php b/yii2-di/test4.php new file mode 100644 index 0000000..3a7bb15 --- /dev/null +++ b/yii2-di/test4.php @@ -0,0 +1,18 @@ +setSingleton('A'); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $j = $di->get('A'); +} +$t2 = microtime(true); + +$results = [ + 'time' => $t2 - $t1, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/yii2-di/test5.php b/yii2-di/test5.php new file mode 100644 index 0000000..c3927db --- /dev/null +++ b/yii2-di/test5.php @@ -0,0 +1,19 @@ +setSingleton('A'); + +$t1 = microtime(true); +for ($i = 0; $i < 10000; $i++) { + $b = $di->get('B'); +} +$t2 = microtime(true); + +$results = [ +'time' => $t2 - $t1, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file diff --git a/yii2-di/test6.php b/yii2-di/test6.php new file mode 100644 index 0000000..7143096 --- /dev/null +++ b/yii2-di/test6.php @@ -0,0 +1,17 @@ +get('J'); +} + + +$results = [ +'time' => 0, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); diff --git a/yii2-di/test6a.php b/yii2-di/test6a.php new file mode 100644 index 0000000..f4ef932 --- /dev/null +++ b/yii2-di/test6a.php @@ -0,0 +1,15 @@ +get('J'); +} + +$results = [ +'time' => 0, +'files' => count(get_included_files()), +'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); diff --git a/zend-servicemanager/test1.php b/zend-servicemanager/test1.php index 4a4fca2..5f25538 100644 --- a/zend-servicemanager/test1.php +++ b/zend-servicemanager/test1.php @@ -1,22 +1,13 @@ setFactory('A', function() { - return new A; - }); - $serviceManager->setShared('A', false); - } -} - - -$config = new ServiceConfiguration(); -$serviceManager = new \Zend\ServiceManager\ServiceManager($config); - - - - +use Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory; +$serviceManager = new \Zend\ServiceManager\ServiceManager([ + 'factories' => [ + 'A' => ReflectionBasedAbstractFactory::class, + ], +]); +$serviceManager->setShared('A', false); for ($i = 0; $i < 10000; $i++) { $a = $serviceManager->get('A'); diff --git a/zend-servicemanager/test2.php b/zend-servicemanager/test2.php index b1c3964..4a46a92 100644 --- a/zend-servicemanager/test2.php +++ b/zend-servicemanager/test2.php @@ -1,18 +1,12 @@ setFactory('A', function() { - return new A; - }); - $serviceManager->setShared('A', false); - } -} - - -$config = new ServiceConfiguration(); -$serviceManager = new \Zend\ServiceManager\ServiceManager($config); - +use Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory; +$serviceManager = new \Zend\ServiceManager\ServiceManager([ + 'factories' => [ + 'A' => ReflectionBasedAbstractFactory::class, + ], +]); +$serviceManager->setShared('A', false); //trigger autoloaders $a = $serviceManager->get('A'); diff --git a/zend-servicemanager/test3.php b/zend-servicemanager/test3.php index 4d4af05..f5604a5 100644 --- a/zend-servicemanager/test3.php +++ b/zend-servicemanager/test3.php @@ -1,74 +1,30 @@ setFactory('A', function() { - return new A; - }); - $serviceManager->setShared('A', false); - - - $serviceManager->setFactory('B', function($serviceManager) { - return new B($serviceManager->get('A')); - }); - $serviceManager->setShared('B', false); - - $serviceManager->setFactory('C', function($serviceManager) { - return new C($serviceManager->get('B')); - }); - - $serviceManager->setShared('C', false); - - $serviceManager->setFactory('D', function($serviceManager) { - return new D($serviceManager->get('C')); - }); - - $serviceManager->setShared('D', false); - - $serviceManager->setFactory('E', function($serviceManager) { - return new E($serviceManager->get('D')); - }); - - $serviceManager->setShared('E', false); - - $serviceManager->setFactory('F', function($serviceManager) { - return new F($serviceManager->get('E')); - }); - - $serviceManager->setShared('F', false); - - $serviceManager->setFactory('G', function($serviceManager) { - return new G($serviceManager->get('F')); - }); - - $serviceManager->setShared('G', false); - - $serviceManager->setFactory('H', function($serviceManager) { - return new H($serviceManager->get('G')); - }); - - $serviceManager->setShared('H', false); - - $serviceManager->setFactory('I', function($serviceManager) { - return new I($serviceManager->get('H')); - }); - - $serviceManager->setShared('I', false); - - $serviceManager->setFactory('J', function($serviceManager) { - return new J($serviceManager->get('I')); - }); - - $serviceManager->setShared('J', false); - - - } -} - - -$config = new ServiceConfiguration(); -$serviceManager = new \Zend\ServiceManager\ServiceManager($config); - +use Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory; +$serviceManager = new \Zend\ServiceManager\ServiceManager([ + 'factories' => [ + 'A' => ReflectionBasedAbstractFactory::class, + 'B' => ReflectionBasedAbstractFactory::class, + 'C' => ReflectionBasedAbstractFactory::class, + 'D' => ReflectionBasedAbstractFactory::class, + 'E' => ReflectionBasedAbstractFactory::class, + 'F' => ReflectionBasedAbstractFactory::class, + 'G' => ReflectionBasedAbstractFactory::class, + 'H' => ReflectionBasedAbstractFactory::class, + 'I' => ReflectionBasedAbstractFactory::class, + 'J' => ReflectionBasedAbstractFactory::class, + ], +]); +$serviceManager->setShared('A', false); +$serviceManager->setShared('B', false); +$serviceManager->setShared('C', false); +$serviceManager->setShared('D', false); +$serviceManager->setShared('E', false); +$serviceManager->setShared('F', false); +$serviceManager->setShared('G', false); +$serviceManager->setShared('H', false); +$serviceManager->setShared('I', false); +$serviceManager->setShared('J', false); //trigger autoloaders $j = $serviceManager->get('J'); diff --git a/zend-servicemanager/test4.php b/zend-servicemanager/test4.php index 58fea48..a0adb84 100644 --- a/zend-servicemanager/test4.php +++ b/zend-servicemanager/test4.php @@ -1,18 +1,12 @@ setFactory('A', function() { - return new A; - }); - $serviceManager->setShared('A', true); - } -} - - -$config = new ServiceConfiguration(); -$serviceManager = new \Zend\ServiceManager\ServiceManager($config); - +use Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory; +$serviceManager = new \Zend\ServiceManager\ServiceManager([ + 'factories' => [ + 'A' => ReflectionBasedAbstractFactory::class, + ], +]); +$serviceManager->setShared('A', true); //trigger autoloaders $a = $serviceManager->get('A'); diff --git a/zend-servicemanager/test5.php b/zend-servicemanager/test5.php index ece9c01..ddb5eff 100644 --- a/zend-servicemanager/test5.php +++ b/zend-servicemanager/test5.php @@ -1,27 +1,14 @@ setFactory('A', function() { - return new A; - }); - $serviceManager->setShared('A', true); - - - $serviceManager->setFactory('B', function($serviceManager) { - return new B($serviceManager->get('A')); - }); - $serviceManager->setShared('B', false); - - - - } -} - - -$config = new ServiceConfiguration(); -$serviceManager = new \Zend\ServiceManager\ServiceManager($config); - +use Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory; +$serviceManager = new \Zend\ServiceManager\ServiceManager([ + 'factories' => [ + 'A' => ReflectionBasedAbstractFactory::class, + 'B' => ReflectionBasedAbstractFactory::class, + ], +]); +$serviceManager->setShared('A', true); +$serviceManager->setShared('B', false); //trigger autoloaders $j = $serviceManager->get('B'); diff --git a/zend-servicemanager/test6.php b/zend-servicemanager/test6.php index 0db75cb..96f2e4c 100644 --- a/zend-servicemanager/test6.php +++ b/zend-servicemanager/test6.php @@ -1,73 +1,30 @@ setFactory('A', function() { - return new A; - }); - $serviceManager->setShared('A', false); - - - $serviceManager->setFactory('B', function($serviceManager) { - return new B($serviceManager->get('A')); - }); - $serviceManager->setShared('B', false); - - $serviceManager->setFactory('C', function($serviceManager) { - return new C($serviceManager->get('B')); - }); - - $serviceManager->setShared('C', false); - - $serviceManager->setFactory('D', function($serviceManager) { - return new D($serviceManager->get('C')); - }); - - $serviceManager->setShared('D', false); - - $serviceManager->setFactory('E', function($serviceManager) { - return new E($serviceManager->get('D')); - }); - - $serviceManager->setShared('E', false); - - $serviceManager->setFactory('F', function($serviceManager) { - return new F($serviceManager->get('E')); - }); - - $serviceManager->setShared('F', false); - - $serviceManager->setFactory('G', function($serviceManager) { - return new G($serviceManager->get('F')); - }); - - $serviceManager->setShared('G', false); - - $serviceManager->setFactory('H', function($serviceManager) { - return new H($serviceManager->get('G')); - }); - - $serviceManager->setShared('H', false); - - $serviceManager->setFactory('I', function($serviceManager) { - return new I($serviceManager->get('H')); - }); - - $serviceManager->setShared('I', false); - - $serviceManager->setFactory('J', function($serviceManager) { - return new J($serviceManager->get('I')); - }); - - $serviceManager->setShared('J', false); - - - } -} - - -$config = new ServiceConfiguration(); -$serviceManager = new \Zend\ServiceManager\ServiceManager($config); +use Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory; +$serviceManager = new \Zend\ServiceManager\ServiceManager([ + 'factories' => [ + 'A' => ReflectionBasedAbstractFactory::class, + 'B' => ReflectionBasedAbstractFactory::class, + 'C' => ReflectionBasedAbstractFactory::class, + 'D' => ReflectionBasedAbstractFactory::class, + 'E' => ReflectionBasedAbstractFactory::class, + 'F' => ReflectionBasedAbstractFactory::class, + 'G' => ReflectionBasedAbstractFactory::class, + 'H' => ReflectionBasedAbstractFactory::class, + 'I' => ReflectionBasedAbstractFactory::class, + 'J' => ReflectionBasedAbstractFactory::class, + ], +]); +$serviceManager->setShared('A', false); +$serviceManager->setShared('B', false); +$serviceManager->setShared('C', false); +$serviceManager->setShared('D', false); +$serviceManager->setShared('E', false); +$serviceManager->setShared('F', false); +$serviceManager->setShared('G', false); +$serviceManager->setShared('H', false); +$serviceManager->setShared('I', false); +$serviceManager->setShared('J', false); for ($i = 0; $i < $argv[1]; $i++) { $j = $serviceManager->get('J'); diff --git a/zend-servicemanager/test6a.php b/zend-servicemanager/test6a.php new file mode 100644 index 0000000..96f2e4c --- /dev/null +++ b/zend-servicemanager/test6a.php @@ -0,0 +1,40 @@ + [ + 'A' => ReflectionBasedAbstractFactory::class, + 'B' => ReflectionBasedAbstractFactory::class, + 'C' => ReflectionBasedAbstractFactory::class, + 'D' => ReflectionBasedAbstractFactory::class, + 'E' => ReflectionBasedAbstractFactory::class, + 'F' => ReflectionBasedAbstractFactory::class, + 'G' => ReflectionBasedAbstractFactory::class, + 'H' => ReflectionBasedAbstractFactory::class, + 'I' => ReflectionBasedAbstractFactory::class, + 'J' => ReflectionBasedAbstractFactory::class, + ], +]); +$serviceManager->setShared('A', false); +$serviceManager->setShared('B', false); +$serviceManager->setShared('C', false); +$serviceManager->setShared('D', false); +$serviceManager->setShared('E', false); +$serviceManager->setShared('F', false); +$serviceManager->setShared('G', false); +$serviceManager->setShared('H', false); +$serviceManager->setShared('I', false); +$serviceManager->setShared('J', false); + +for ($i = 0; $i < $argv[1]; $i++) { + $j = $serviceManager->get('J'); +} + + +$results = [ + 'time' => 0, + 'files' => count(get_included_files()), + 'memory' => memory_get_peak_usage()/1024/1024 +]; + +echo json_encode($results); \ No newline at end of file