This repository has been archived by the owner on Feb 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…rformance-optimization Feature - #64 additional aliases performance optimization
- Loading branch information
Showing
9 changed files
with
322 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
namespace ZendBench\ServiceManager; | ||
|
||
use PhpBench\Benchmark\Metadata\Annotations\Iterations; | ||
use PhpBench\Benchmark\Metadata\Annotations\Revs; | ||
use PhpBench\Benchmark\Metadata\Annotations\Warmup; | ||
use Zend\ServiceManager\ServiceManager; | ||
|
||
/** | ||
* @Revs(1000) | ||
* @Iterations(20) | ||
* @Warmup(2) | ||
*/ | ||
class FetchCachedServicesBench | ||
{ | ||
/** | ||
* @var ServiceManager | ||
*/ | ||
private $sm; | ||
|
||
public function __construct() | ||
{ | ||
$this->sm = new ServiceManager([ | ||
'factories' => [ | ||
'factory1' => BenchAsset\FactoryFoo::class, | ||
], | ||
'invokables' => [ | ||
'invokable1' => BenchAsset\Foo::class, | ||
], | ||
'services' => [ | ||
'service1' => new \stdClass(), | ||
], | ||
'aliases' => [ | ||
'alias1' => 'service1', | ||
'recursiveAlias1' => 'alias1', | ||
'recursiveAlias2' => 'recursiveAlias1', | ||
], | ||
'abstract_factories' => [ | ||
BenchAsset\AbstractFactoryFoo::class | ||
] | ||
]); | ||
|
||
// forcing initialization of all the services | ||
$this->sm->get('factory1'); | ||
$this->sm->get('invokable1'); | ||
$this->sm->get('service1'); | ||
$this->sm->get('alias1'); | ||
$this->sm->get('recursiveAlias1'); | ||
$this->sm->get('recursiveAlias2'); | ||
} | ||
|
||
public function benchFetchFactory1() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->get('factory1'); | ||
} | ||
|
||
public function benchFetchInvokable1() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->get('invokable1'); | ||
} | ||
|
||
public function benchFetchService1() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->get('service1'); | ||
} | ||
|
||
public function benchFetchAlias1() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->get('alias1'); | ||
} | ||
|
||
public function benchFetchRecursiveAlias1() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->get('recursiveAlias1'); | ||
} | ||
|
||
public function benchFetchRecursiveAlias2() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->get('recursiveAlias2'); | ||
} | ||
|
||
public function benchFetchAbstractFactoryService() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->get('foo'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace ZendBench\ServiceManager; | ||
|
||
use PhpBench\Benchmark\Metadata\Annotations\Iterations; | ||
use PhpBench\Benchmark\Metadata\Annotations\Revs; | ||
use PhpBench\Benchmark\Metadata\Annotations\Warmup; | ||
use Zend\ServiceManager\ServiceManager; | ||
|
||
/** | ||
* @Revs(100) | ||
* @Iterations(20) | ||
* @Warmup(2) | ||
*/ | ||
class FetchNewServiceManagerBench | ||
{ | ||
const NUM_SERVICES = 1000; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $config = []; | ||
|
||
public function __construct() | ||
{ | ||
$config = [ | ||
'factories' => [], | ||
'invokables' => [], | ||
'services' => [], | ||
'aliases' => [], | ||
'abstract_factories' => [ | ||
BenchAsset\AbstractFactoryFoo::class, | ||
], | ||
]; | ||
|
||
$service = new \stdClass(); | ||
|
||
for ($i = 0; $i <= self::NUM_SERVICES; $i++) { | ||
$config['factories']["factory_$i"] = BenchAsset\FactoryFoo::class; | ||
$config['invokables']["invokable_$i"] = BenchAsset\Foo::class; | ||
$config['services']["service_$i"] = $service; | ||
$config['aliases']["alias_$i"] = "service_$i"; | ||
} | ||
$this->config = $config; | ||
} | ||
|
||
public function benchFetchServiceManagerCreation() | ||
{ | ||
new ServiceManager($this->config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
namespace ZendBench\ServiceManager; | ||
|
||
use PhpBench\Benchmark\Metadata\Annotations\Iterations; | ||
use PhpBench\Benchmark\Metadata\Annotations\Revs; | ||
use PhpBench\Benchmark\Metadata\Annotations\Warmup; | ||
use Zend\ServiceManager\ServiceManager; | ||
|
||
/** | ||
* @Revs(1000) | ||
* @Iterations(10) | ||
* @Warmup(2) | ||
*/ | ||
class FetchNewServicesBench | ||
{ | ||
/** | ||
* @var ServiceManager | ||
*/ | ||
private $sm; | ||
|
||
public function __construct() | ||
{ | ||
$this->sm = new ServiceManager([ | ||
'factories' => [ | ||
'factory1' => BenchAsset\FactoryFoo::class, | ||
], | ||
'invokables' => [ | ||
'invokable1' => BenchAsset\Foo::class, | ||
], | ||
'services' => [ | ||
'service1' => new \stdClass(), | ||
], | ||
'aliases' => [ | ||
'factoryAlias1' => 'factory1', | ||
'recursiveFactoryAlias1' => 'factoryAlias1', | ||
'recursiveFactoryAlias2' => 'recursiveFactoryAlias1', | ||
], | ||
'abstract_factories' => [ | ||
BenchAsset\AbstractFactoryFoo::class | ||
], | ||
]); | ||
} | ||
|
||
public function benchFetchFactory1() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->get('factory1'); | ||
} | ||
|
||
public function benchBuildFactory1() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->build('factory1'); | ||
} | ||
|
||
public function benchFetchInvokable1() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->get('invokable1'); | ||
} | ||
|
||
public function benchBuildInvokable1() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->build('invokable1'); | ||
} | ||
|
||
public function benchFetchService1() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->get('service1'); | ||
} | ||
|
||
public function benchFetchFactoryAlias1() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->build('factoryAlias1'); | ||
} | ||
|
||
public function benchBuildFactoryAlias1() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->build('factoryAlias1'); | ||
} | ||
|
||
public function benchFetchRecursiveFactoryAlias1() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->build('recursiveFactoryAlias1'); | ||
} | ||
|
||
public function benchBuildRecursiveFactoryAlias1() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->build('recursiveFactoryAlias1'); | ||
} | ||
|
||
public function benchFetchRecursiveFactoryAlias2() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->build('recursiveFactoryAlias2'); | ||
} | ||
|
||
public function benchBuildRecursiveFactoryAlias2() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->build('recursiveFactoryAlias2'); | ||
} | ||
|
||
public function benchFetchAbstractFactoryFoo() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->get('foo'); | ||
} | ||
|
||
public function benchBuildAbstractFactoryFoo() | ||
{ | ||
// @todo @link https://github.com/phpbench/phpbench/issues/304 | ||
$sm = clone $this->sm; | ||
|
||
$sm->build('foo'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.