Skip to content

Commit 6d44d98

Browse files
committed
Inital
0 parents  commit 6d44d98

10 files changed

+193
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
composer.lock

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
PHP Container Benchmarking Suite
2+
================================
3+
4+
This benchmarking suite compares PHP Dependency Injection Containers.
5+
6+
Including:
7+
8+
- [PHP-DI](https://github.com/PHP-DI/PHP-DI).
9+
- [Symfony Dependency Injection](https://github.com/symfony/DependencyInjection).
10+
- [Pimple](https://github.com/silexphp/Pimple).
11+
- [PHPBench Container](https://github.com/phpbench/phpbench).
12+
13+
Note that PHPBench Container is not the Not a "real" container, but a minimal
14+
ad-hoc call-back based container used by PHPBench itself.
15+
16+
Run the Benchmarks
17+
------------------
18+
19+
````bash
20+
$ composer install
21+
$ ./vendor/bin/phpbench run --report=containers
22+
````
23+

benchmarks/AbstractBench.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace PhpBench\Benchmarks\Container;
4+
5+
abstract class AbstractBench
6+
{
7+
abstract public function benchGet();
8+
}

benchmarks/PhpBenchDiBench.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace PhpBench\Benchmarks\Container;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use PhpBench\Container;
7+
8+
/**
9+
* @beforeMethod init
10+
* @iterations 4
11+
*/
12+
class PhpBenchDiBench extends AbstractBench
13+
{
14+
private $container;
15+
16+
public function init()
17+
{
18+
$container = new Container();
19+
$container->register('bicycle_factory', function ($c) {
20+
return new \PhpBench\Benchmarks\Container\Acme\BicycleFactory;
21+
});
22+
$this->container = $container;
23+
}
24+
25+
/**
26+
* @revs 1000
27+
*/
28+
public function benchGet()
29+
{
30+
$this->container->get('bicycle_factory');
31+
}
32+
}
33+

benchmarks/PhpDiBench.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace PhpBench\Benchmarks\Container;
4+
5+
use DI\ContainerBuilder;
6+
7+
/**
8+
* @beforeMethod init
9+
* @iterations 4
10+
*/
11+
class PhpDiBench extends AbstractBench
12+
{
13+
private $container;
14+
15+
public function init()
16+
{
17+
$builder = new ContainerBuilder();
18+
19+
$this->container = $builder->build();
20+
$this->container->set('bicycle_factory', \DI\object('PhpBench\Benchmarks\Container\Acme\BicycleFactory'));
21+
}
22+
23+
/**
24+
* @revs 1000
25+
*/
26+
public function benchGet()
27+
{
28+
$this->container->get('bicycle_factory');
29+
}
30+
}

benchmarks/PimpleDiBench.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace PhpBench\Benchmarks\Container;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Pimple\Container;
7+
8+
/**
9+
* @beforeMethod init
10+
* @iterations 4
11+
*/
12+
class PimpleBench extends AbstractBench
13+
{
14+
private $container;
15+
16+
public function init()
17+
{
18+
$container = new Container();
19+
$container['bicycle_factory'] = function ($c) {
20+
return new \PhpBench\Benchmarks\Container\Acme\BicycleFactory;
21+
};
22+
$this->container = $container;
23+
}
24+
25+
/**
26+
* @revs 1000
27+
*/
28+
public function benchGet()
29+
{
30+
$this->container['bicycle_factory'];
31+
}
32+
}
33+

benchmarks/SymfonyDiBench.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace PhpBench\Benchmarks\Container;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
7+
/**
8+
* @beforeMethod init
9+
* @iterations 4
10+
*/
11+
class SymfonyDiBench extends AbstractBench
12+
{
13+
private $container;
14+
15+
public function init()
16+
{
17+
$builder = new ContainerBuilder();
18+
$builder->register('bicycle_factory', 'PhpBench\Benchmarks\Container\Acme\BicycleFactory');
19+
$this->container = $builder;
20+
}
21+
22+
/**
23+
* @revs 1000
24+
*/
25+
public function benchGet()
26+
{
27+
$this->container->get('bicycle_factory');
28+
}
29+
}
30+

composer.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "phpbench/benchmark-containers",
3+
"require": {
4+
"phpbench/phpbench": "@dev",
5+
"php-di/php-di": "^5.0.0",
6+
"symfony/dependency-injection": "^2.7.0",
7+
"pimple/pimple": "^3.0.0"
8+
},
9+
"autoload": {
10+
"psr-4": {
11+
"PhpBench\\Benchmarks\\Container\\": "benchmarks",
12+
"PhpBench\\Benchmarks\\Container\\Acme\\": "lib"
13+
}
14+
}
15+
}

lib/BicycleFactory.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace PhpBench\Benchmarks\Container\Acme;
4+
5+
class BicycleFactory
6+
{
7+
}

phpbench.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"path": "benchmarks",
3+
"bootstrap": "vendor/autoload.php",
4+
"reports": {
5+
"containers": {
6+
"extends": "aggregate",
7+
"exclude": ["subject", "group", "params"],
8+
"title": "Container get - no optimization",
9+
"description": "Retrieve a single class without any constructor arguments from an uncompiled container"
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)