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.
Merge pull request #38 from ezimuel/feature/bench
Add the benchmarks
- Loading branch information
Showing
6 changed files
with
146 additions
and
2 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,21 @@ | ||
<?php | ||
namespace ZendBench\ServiceManager\BenchAsset; | ||
|
||
use Zend\ServiceManager\Factory\AbstractFactoryInterface; | ||
use Interop\Container\ContainerInterface; | ||
|
||
class AbstractFactoryFoo implements AbstractFactoryInterface | ||
{ | ||
public function canCreateServiceWithName(ContainerInterface $container, $requestedName) | ||
{ | ||
return ($requestedName === 'foo'); | ||
} | ||
|
||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) | ||
{ | ||
if ($requestedName === 'foo') { | ||
return new Foo($options); | ||
} | ||
return false; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
namespace ZendBench\ServiceManager\BenchAsset; | ||
|
||
use Zend\ServiceManager\Factory\FactoryInterface; | ||
use Interop\Container\ContainerInterface; | ||
|
||
class FactoryFoo implements FactoryInterface | ||
{ | ||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) | ||
{ | ||
return new Foo($options); | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
namespace ZendBench\ServiceManager\BenchAsset; | ||
|
||
class Foo | ||
{ | ||
protected $options; | ||
|
||
public function __construct($options = null) | ||
{ | ||
$this->options = $options; | ||
} | ||
} |
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,84 @@ | ||
<?php | ||
|
||
namespace ZendBench\ServiceManager; | ||
|
||
use Athletic\AthleticEvent; | ||
use Zend\ServiceManager\ServiceManager; | ||
|
||
class FetchServices extends AthleticEvent | ||
{ | ||
const NUM_SERVICES = 1000; | ||
|
||
/** | ||
* @var ServiceManager | ||
*/ | ||
protected $sm; | ||
|
||
protected function getConfig() | ||
{ | ||
$config = []; | ||
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"] = $this; | ||
$config['aliases']["alias_$i"] = "service_$i"; | ||
} | ||
$config['abstract_factories'] = [ BenchAsset\AbstractFactoryFoo::class ]; | ||
return $config; | ||
} | ||
|
||
public function classSetUp() | ||
{ | ||
$this->sm = new ServiceManager($this->getConfig()); | ||
} | ||
|
||
/** | ||
* Fetch the factory services | ||
* | ||
* @iterations 5000 | ||
*/ | ||
public function fetchFactoryService() | ||
{ | ||
$result = $this->sm->get('factory_' . rand(0, self::NUM_SERVICES)); | ||
} | ||
|
||
/** | ||
* Fetch the invokable services | ||
* | ||
* @iterations 5000 | ||
*/ | ||
public function fetchInvokableService() | ||
{ | ||
$result = $this->sm->get('invokable_' . rand(0, self::NUM_SERVICES)); | ||
} | ||
|
||
/** | ||
* Fetch the services | ||
* | ||
* @iterations 5000 | ||
*/ | ||
public function fetchService() | ||
{ | ||
$result = $this->sm->get('service_' . rand(0, self::NUM_SERVICES)); | ||
} | ||
|
||
/** | ||
* Fetch the alias services | ||
* | ||
* @iterations 5000 | ||
*/ | ||
public function fetchAliasService() | ||
{ | ||
$result = $this->sm->get('alias_' . rand(0, self::NUM_SERVICES)); | ||
} | ||
|
||
/** | ||
* Fetch the abstract factory services | ||
* | ||
* @iterations 5000 | ||
*/ | ||
public function fetchAbstractFactoryService() | ||
{ | ||
$result = $this->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