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

Commit 6bf0ced

Browse files
committed
Merge branch 'hotfix/39'
Close #39
2 parents f7225b1 + 14910f8 commit 6bf0ced

File tree

6 files changed

+136
-2
lines changed

6 files changed

+136
-2
lines changed

.php_cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
$finder = Symfony\CS\Finder\DefaultFinder::create()
3+
->in('benchmarks')
34
->in('src')
45
->in('test')
56
->notPath('TestAsset')
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
namespace ZendBench\ServiceManager\BenchAsset;
3+
4+
use Zend\ServiceManager\AbstractFactoryInterface;
5+
use Zend\ServiceManager\ServiceLocatorInterface;
6+
7+
class AbstractFactoryFoo implements AbstractFactoryInterface
8+
{
9+
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
10+
{
11+
if ($name != 'foo') {
12+
return false;
13+
}
14+
return true;
15+
}
16+
17+
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
18+
{
19+
return new Foo();
20+
}
21+
}

benchmarks/BenchAsset/FactoryFoo.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
namespace ZendBench\ServiceManager\BenchAsset;
3+
4+
use Zend\ServiceManager\FactoryInterface;
5+
use Zend\ServiceManager\ServiceLocatorInterface;
6+
7+
class FactoryFoo implements FactoryInterface
8+
{
9+
public function createService(ServiceLocatorInterface $serviceLocator)
10+
{
11+
return new Foo();
12+
}
13+
}

benchmarks/BenchAsset/Foo.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace ZendBench\ServiceManager\BenchAsset;
3+
4+
class Foo
5+
{
6+
protected $options;
7+
8+
public function __construct($options = null)
9+
{
10+
$this->options = $options;
11+
}
12+
}

benchmarks/FetchServices.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace ZendBench\ServiceManager;
4+
5+
use Athletic\AthleticEvent;
6+
use Zend\ServiceManager\ServiceManager;
7+
use Zend\ServiceManager\Config;
8+
9+
class FetchServices extends AthleticEvent
10+
{
11+
const NUM_SERVICES = 1000;
12+
13+
/**
14+
* @var ServiceManager
15+
*/
16+
protected $sm;
17+
18+
protected function getConfig()
19+
{
20+
$config = [];
21+
for ($i = 0; $i <= self::NUM_SERVICES; $i++) {
22+
$config['factories']["factory_$i"] = BenchAsset\FactoryFoo::class;
23+
$config['invokables']["invokable_$i"] = BenchAsset\Foo::class;
24+
$config['services']["service_$i"] = $this;
25+
$config['aliases']["alias_$i"] = "service_$i";
26+
}
27+
$config['abstract_factories'] = [ BenchAsset\AbstractFactoryFoo::class ];
28+
return $config;
29+
}
30+
31+
public function classSetUp()
32+
{
33+
$this->sm = new ServiceManager(new Config($this->getConfig()));
34+
}
35+
36+
/**
37+
* Fetch the factory services
38+
*
39+
* @iterations 5000
40+
*/
41+
public function fetchFactoryService()
42+
{
43+
$result = $this->sm->get('factory_' . rand(0, self::NUM_SERVICES));
44+
}
45+
46+
/**
47+
* Fetch the invokable services
48+
*
49+
* @iterations 5000
50+
*/
51+
public function fetchInvokableService()
52+
{
53+
$result = $this->sm->get('invokable_' . rand(0, self::NUM_SERVICES));
54+
}
55+
56+
/**
57+
* Fetch the services
58+
*
59+
* @iterations 5000
60+
*/
61+
public function fetchService()
62+
{
63+
$result = $this->sm->get('service_' . rand(0, self::NUM_SERVICES));
64+
}
65+
66+
/**
67+
* Fetch the alias services
68+
*
69+
* @iterations 5000
70+
*/
71+
public function fetchAliasService()
72+
{
73+
$result = $this->sm->get('alias_' . rand(0, self::NUM_SERVICES));
74+
}
75+
76+
/**
77+
* Fetch the abstract factory services
78+
*
79+
* @iterations 5000
80+
*/
81+
public function fetchAbstractFactoryService()
82+
{
83+
$result = $this->sm->get('foo');
84+
}
85+
}

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"zendframework/zend-di": "~2.5",
2121
"zendframework/zend-mvc": "~2.5",
2222
"fabpot/php-cs-fixer": "1.7.*",
23-
"phpunit/PHPUnit": "~4.0"
23+
"phpunit/PHPUnit": "~4.0",
24+
"athletic/athletic": "dev-master"
2425
},
2526
"suggest": {
2627
"ocramius/proxy-manager": "ProxyManager 0.5.* to handle lazy initialization of services",
@@ -36,7 +37,8 @@
3637
},
3738
"autoload-dev": {
3839
"psr-4": {
39-
"ZendTest\\ServiceManager\\": "test/"
40+
"ZendTest\\ServiceManager\\": "test/",
41+
"ZendBench\\ServiceManager\\": "benchmarks/"
4042
}
4143
}
4244
}

0 commit comments

Comments
 (0)