|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ZendBench\ServiceManager; |
| 4 | + |
| 5 | +use PhpBench\Benchmark\Metadata\Annotations\Iterations; |
| 6 | +use PhpBench\Benchmark\Metadata\Annotations\Revs; |
| 7 | +use PhpBench\Benchmark\Metadata\Annotations\Warmup; |
| 8 | +use Zend\ServiceManager\ServiceManager; |
| 9 | + |
| 10 | +/** |
| 11 | + * @Revs(1000) |
| 12 | + * @Iterations(10) |
| 13 | + * @Warmup(2) |
| 14 | + */ |
| 15 | +class SetNewServicesBench |
| 16 | +{ |
| 17 | + const NUM_SERVICES = 100; |
| 18 | + |
| 19 | + /** |
| 20 | + * @var ServiceManager |
| 21 | + */ |
| 22 | + private $sm; |
| 23 | + |
| 24 | + public function __construct() |
| 25 | + { |
| 26 | + |
| 27 | + $config = [ |
| 28 | + 'factories' => [ |
| 29 | + 'factory1' => BenchAsset\FactoryFoo::class, |
| 30 | + ], |
| 31 | + 'invokables' => [ |
| 32 | + 'invokable1' => BenchAsset\Foo::class, |
| 33 | + ], |
| 34 | + 'services' => [ |
| 35 | + 'service1' => new \stdClass(), |
| 36 | + ], |
| 37 | + 'aliases' => [ |
| 38 | + 'factoryAlias1' => 'factory1', |
| 39 | + 'recursiveFactoryAlias1' => 'factoryAlias1', |
| 40 | + 'recursiveFactoryAlias2' => 'recursiveFactoryAlias1', |
| 41 | + ], |
| 42 | + 'abstract_factories' => [ |
| 43 | + BenchAsset\AbstractFactoryFoo::class |
| 44 | + ], |
| 45 | + ]; |
| 46 | + |
| 47 | + $service = new \stdClass(); |
| 48 | + for ($i = 0; $i <= self::NUM_SERVICES; $i++) { |
| 49 | + $config['factories']["factory_$i"] = BenchAsset\FactoryFoo::class; |
| 50 | + $config['aliases']["alias_$i"] = "service_$i"; |
| 51 | + } |
| 52 | + |
| 53 | + $this->sm = new ServiceManager($config); |
| 54 | + } |
| 55 | + |
| 56 | + public function benchSetFactory() |
| 57 | + { |
| 58 | + // @todo @link https://github.com/phpbench/phpbench/issues/304 |
| 59 | + $sm = clone $this->sm; |
| 60 | + |
| 61 | + $sm->setFactory('factory2', BenchAsset\FactoryFoo::class); |
| 62 | + } |
| 63 | + |
| 64 | + public function benchSetAlias() |
| 65 | + { |
| 66 | + // @todo @link https://github.com/phpbench/phpbench/issues/304 |
| 67 | + $sm = clone $this->sm; |
| 68 | + |
| 69 | + $sm->setAlias('factoryAlias2', 'factory1'); |
| 70 | + } |
| 71 | + |
| 72 | + public function benchSetAliasOverrided() |
| 73 | + { |
| 74 | + // @todo @link https://github.com/phpbench/phpbench/issues/304 |
| 75 | + $sm = clone $this->sm; |
| 76 | + |
| 77 | + $sm->setAlias('recursiveFactoryAlias1', 'factory1'); |
| 78 | + } |
| 79 | +} |
0 commit comments