Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit 59d699b

Browse files
committed
Merge branch 'feature/#217-add-benchmark-for-servicemanager-has' into develop
2 parents 0c328a7 + 354c498 commit 59d699b

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

benchmarks/HasBench.php

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
/**
3+
* @link http://github.com/zendframework/zend-servicemanager for the canonical source repository
4+
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license http://framework.zend.com/license/new-bsd New BSD License
6+
*/
7+
8+
namespace ZendBench\ServiceManager;
9+
10+
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
11+
use PhpBench\Benchmark\Metadata\Annotations\Revs;
12+
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
13+
use Zend\ServiceManager\ServiceManager;
14+
15+
/**
16+
* @Revs(1000)
17+
* @Iterations(20)
18+
* @Warmup(2)
19+
*/
20+
class HasBench
21+
{
22+
/**
23+
* @var ServiceManager
24+
*/
25+
private $sm;
26+
27+
public function __construct()
28+
{
29+
$this->sm = new ServiceManager([
30+
'factories' => [
31+
'factory1' => BenchAsset\FactoryFoo::class,
32+
],
33+
'invokables' => [
34+
'invokable1' => BenchAsset\Foo::class,
35+
],
36+
'services' => [
37+
'service1' => new \stdClass(),
38+
],
39+
'aliases' => [
40+
'alias1' => 'service1',
41+
'recursiveAlias1' => 'alias1',
42+
'recursiveAlias2' => 'recursiveAlias1',
43+
],
44+
'abstract_factories' => [
45+
BenchAsset\AbstractFactoryFoo::class
46+
]
47+
]);
48+
49+
// forcing initialization of all the services
50+
$this->sm->get('factory1');
51+
$this->sm->get('invokable1');
52+
$this->sm->get('service1');
53+
$this->sm->get('alias1');
54+
$this->sm->get('recursiveAlias1');
55+
$this->sm->get('recursiveAlias2');
56+
}
57+
58+
public function benchHasFactory1()
59+
{
60+
// @todo @link https://github.com/phpbench/phpbench/issues/304
61+
$sm = clone $this->sm;
62+
63+
$sm->has('factory1');
64+
}
65+
66+
public function benchHasInvokable1()
67+
{
68+
// @todo @link https://github.com/phpbench/phpbench/issues/304
69+
$sm = clone $this->sm;
70+
71+
$sm->has('invokable1');
72+
}
73+
74+
public function benchHasService1()
75+
{
76+
// @todo @link https://github.com/phpbench/phpbench/issues/304
77+
$sm = clone $this->sm;
78+
79+
$sm->has('service1');
80+
}
81+
82+
public function benchHasAlias1()
83+
{
84+
// @todo @link https://github.com/phpbench/phpbench/issues/304
85+
$sm = clone $this->sm;
86+
87+
$sm->has('alias1');
88+
}
89+
90+
public function benchHasRecursiveAlias1()
91+
{
92+
// @todo @link https://github.com/phpbench/phpbench/issues/304
93+
$sm = clone $this->sm;
94+
95+
$sm->has('recursiveAlias1');
96+
}
97+
98+
public function benchHasRecursiveAlias2()
99+
{
100+
// @todo @link https://github.com/phpbench/phpbench/issues/304
101+
$sm = clone $this->sm;
102+
103+
$sm->has('recursiveAlias2');
104+
}
105+
106+
public function benchHasAbstractFactory()
107+
{
108+
// @todo @link https://github.com/phpbench/phpbench/issues/304
109+
$sm = clone $this->sm;
110+
111+
$sm->has('foo');
112+
}
113+
114+
public function benchHasNot()
115+
{
116+
// @todo @link https://github.com/phpbench/phpbench/issues/304
117+
$sm = clone $this->sm;
118+
119+
$sm->has('42');
120+
}
121+
}

0 commit comments

Comments
 (0)