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.
More and better benchmarking of new abstract factories
This patch provides more benchmarking for the new abstract factories, pulling them each into separate benchmark classes to ensure they operate in isolation to other abstract factories, and to allow seeing baseline timings. Additionally, each has two benchmarking suites: one demonstrating usage as an abstract factory, another demonstrating usage as a mapped factory. The basic results are that the `ConfigAbstractFactory` operates at roughly the same speed as a normal abstract factory that contains logic for creating an instance. The `ReflectionBasedAbstractFactory` is about 100% slower when at least one dependency is present (and ever-so-slightly faster when no dependencies are present).
- Loading branch information
1 parent
f2036a8
commit 15712f9
Showing
9 changed files
with
406 additions
and
49 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 | ||
/** | ||
* @link http://github.com/zendframework/zend-servicemanager for the canonical source repository | ||
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendBench\ServiceManager\BenchAsset; | ||
|
||
class Dependency | ||
{ | ||
} |
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 | ||
/** | ||
* @link http://github.com/zendframework/zend-servicemanager for the canonical source repository | ||
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendBench\ServiceManager\BenchAsset; | ||
|
||
class ServiceDependingOnConfig | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $config; | ||
|
||
public function __construct(array $config) | ||
{ | ||
$this->config = $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,24 @@ | ||
<?php | ||
/** | ||
* @link http://github.com/zendframework/zend-servicemanager for the canonical source repository | ||
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendBench\ServiceManager\BenchAsset; | ||
|
||
class ServiceWithDependency | ||
{ | ||
/** | ||
* @var Dependency | ||
*/ | ||
private $dependency; | ||
|
||
/** | ||
* @param Dependency $dependency | ||
*/ | ||
public function __construct(Dependency $dependency) | ||
{ | ||
$this->dependency = $dependency; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
benchmarks/FetchNewServiceUsingConfigAbstractFactoryAsFactoryBench.php
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,93 @@ | ||
<?php | ||
/** | ||
* @link http://github.com/zendframework/zend-servicemanager for the canonical source repository | ||
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendBench\ServiceManager; | ||
|
||
use PhpBench\Benchmark\Metadata\Annotations\Iterations; | ||
use PhpBench\Benchmark\Metadata\Annotations\Revs; | ||
use PhpBench\Benchmark\Metadata\Annotations\Warmup; | ||
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory; | ||
use Zend\ServiceManager\ServiceManager; | ||
|
||
/** | ||
* @Revs(1000) | ||
* @Iterations(10) | ||
* @Warmup(2) | ||
*/ | ||
class FetchNewServiceUsingConfigAbstractFactoryAsFactoryBench | ||
{ | ||
/** | ||
* @var ServiceManager | ||
*/ | ||
private $sm; | ||
|
||
public function __construct() | ||
{ | ||
$this->sm = new ServiceManager([ | ||
'services' => [ | ||
'config' => [ | ||
ConfigAbstractFactory::class => [ | ||
BenchAsset\Dependency::class => [], | ||
BenchAsset\ServiceWithDependency::class => [ | ||
BenchAsset\Dependency::class, | ||
], | ||
BenchAsset\ServiceDependingOnConfig::class => [ | ||
'config', | ||
], | ||
], | ||
], | ||
], | ||
'factories' => [ | ||
BenchAsset\Dependency::class => ConfigAbstractFactory::class, | ||
BenchAsset\ServiceWithDependency::class => ConfigAbstractFactory::class, | ||
BenchAsset\ServiceDependingOnConfig::class => ConfigAbstractFactory::class, | ||
], | ||
]); | ||
} | ||
|
||
public function benchFetchServiceWithNoDependencies() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->get(BenchAsset\Dependency::class); | ||
} | ||
|
||
public function benchBuildServiceWithNoDependencies() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->build(BenchAsset\Dependency::class); | ||
} | ||
|
||
public function benchFetchServiceDependingOnConfig() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->get(BenchAsset\ServiceDependingOnConfig::class); | ||
} | ||
|
||
public function benchBuildServiceDependingOnConfig() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->build(BenchAsset\ServiceDependingOnConfig::class); | ||
} | ||
|
||
public function benchFetchServiceWithDependency() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->get(BenchAsset\ServiceWithDependency::class); | ||
} | ||
|
||
public function benchBuildServiceWithDependency() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->build(BenchAsset\ServiceWithDependency::class); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
benchmarks/FetchNewServiceUsingReflectionAbstractFactoryAsFactoryBench.php
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,83 @@ | ||
<?php | ||
/** | ||
* @link http://github.com/zendframework/zend-servicemanager for the canonical source repository | ||
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendBench\ServiceManager; | ||
|
||
use PhpBench\Benchmark\Metadata\Annotations\Iterations; | ||
use PhpBench\Benchmark\Metadata\Annotations\Revs; | ||
use PhpBench\Benchmark\Metadata\Annotations\Warmup; | ||
use Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory; | ||
use Zend\ServiceManager\ServiceManager; | ||
|
||
/** | ||
* @Revs(1000) | ||
* @Iterations(10) | ||
* @Warmup(2) | ||
*/ | ||
class FetchNewServiceUsingReflectionAbstractFactoryAsFactoryBench | ||
{ | ||
/** | ||
* @var ServiceManager | ||
*/ | ||
private $sm; | ||
|
||
public function __construct() | ||
{ | ||
$this->sm = new ServiceManager([ | ||
'services' => [ | ||
'config' => [], | ||
], | ||
'factories' => [ | ||
BenchAsset\Dependency::class => ReflectionBasedAbstractFactory::class, | ||
BenchAsset\ServiceWithDependency::class => ReflectionBasedAbstractFactory::class, | ||
BenchAsset\ServiceDependingOnConfig::class => ReflectionBasedAbstractFactory::class, | ||
], | ||
]); | ||
} | ||
|
||
public function benchFetchServiceWithNoDependencies() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->get(BenchAsset\Dependency::class); | ||
} | ||
|
||
public function benchBuildServiceWithNoDependencies() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->build(BenchAsset\Dependency::class); | ||
} | ||
|
||
public function benchFetchServiceDependingOnConfig() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->get(BenchAsset\ServiceDependingOnConfig::class); | ||
} | ||
|
||
public function benchBuildServiceDependingOnConfig() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->build(BenchAsset\ServiceDependingOnConfig::class); | ||
} | ||
|
||
public function benchFetchServiceWithDependency() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->get(BenchAsset\ServiceWithDependency::class); | ||
} | ||
|
||
public function benchBuildServiceWithDependency() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->build(BenchAsset\ServiceWithDependency::class); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
benchmarks/FetchNewServiceViaConfigAbstractFactoryBench.php
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,91 @@ | ||
<?php | ||
/** | ||
* @link http://github.com/zendframework/zend-servicemanager for the canonical source repository | ||
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendBench\ServiceManager; | ||
|
||
use PhpBench\Benchmark\Metadata\Annotations\Iterations; | ||
use PhpBench\Benchmark\Metadata\Annotations\Revs; | ||
use PhpBench\Benchmark\Metadata\Annotations\Warmup; | ||
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory; | ||
use Zend\ServiceManager\ServiceManager; | ||
|
||
/** | ||
* @Revs(1000) | ||
* @Iterations(10) | ||
* @Warmup(2) | ||
*/ | ||
class FetchNewServiceViaConfigAbstractFactoryBench | ||
{ | ||
/** | ||
* @var ServiceManager | ||
*/ | ||
private $sm; | ||
|
||
public function __construct() | ||
{ | ||
$this->sm = new ServiceManager([ | ||
'services' => [ | ||
'config' => [ | ||
ConfigAbstractFactory::class => [ | ||
BenchAsset\Dependency::class => [], | ||
BenchAsset\ServiceWithDependency::class => [ | ||
BenchAsset\Dependency::class, | ||
], | ||
BenchAsset\ServiceDependingOnConfig::class => [ | ||
'config', | ||
], | ||
], | ||
], | ||
], | ||
'abstract_factories' => [ | ||
ConfigAbstractFactory::class, | ||
], | ||
]); | ||
} | ||
|
||
public function benchFetchServiceWithNoDependencies() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->get(BenchAsset\Dependency::class); | ||
} | ||
|
||
public function benchBuildServiceWithNoDependencies() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->build(BenchAsset\Dependency::class); | ||
} | ||
|
||
public function benchFetchServiceDependingOnConfig() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->get(BenchAsset\ServiceDependingOnConfig::class); | ||
} | ||
|
||
public function benchBuildServiceDependingOnConfig() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->build(BenchAsset\ServiceDependingOnConfig::class); | ||
} | ||
|
||
public function benchFetchServiceWithDependency() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->get(BenchAsset\ServiceWithDependency::class); | ||
} | ||
|
||
public function benchBuildServiceWithDependency() | ||
{ | ||
$sm = clone $this->sm; | ||
|
||
$sm->build(BenchAsset\ServiceWithDependency::class); | ||
} | ||
} |
Oops, something went wrong.