Skip to content

Commit

Permalink
Add benckmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
emonkak committed Dec 15, 2015
1 parent dfd36d7 commit 3493e4f
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ cache:

before_script:
- sudo apt-get -qq update && sudo apt-get -qq install graphviz
- sh -c "if [ $TRAVIS_PHP_VERSION != 'hhvm' ]; then if [ ${TRAVIS_PHP_VERSION%%.*} -ge 7 ]; then echo "yes\n" | pecl install apcu; else echo "yes\n" | pecl install apcu-4.0.10; fi; echo 'extension=apcu.so' >> ./php.ini; else echo 'extension=apc.so' >> ./php.ini; fi"
- composer install --prefer-source
- sh -c "if [ $TRAVIS_PHP_VERSION != 'hhvm' ]; then if [ ${TRAVIS_PHP_VERSION//./} -ge 70 ]; then echo "yes\n" | pecl install apcu; else echo "yes\n" | pecl install apcu-4.0.10; fi; echo 'extension=apcu.so' >> ./php.ini; else echo 'extension=apc.so' >> ./php.ini; fi"
- composer install --prefer-source --ignore-platform-reqs
- sh -c "if [ $TRAVIS_PHP_VERSION != 'hhvm' ]; then phpenv config-add ./php.ini; fi"

script:
Expand Down
83 changes: 47 additions & 36 deletions benchmarks/AuraDiEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Athletic\AthleticEvent;
use Aura\Di\Container;
use Aura\Di\Forge;
use Aura\Di\Factory;
use Aura\Di\Config;
use Emonkak\Di\Benchmarks\Fixtures\Foo;

Expand All @@ -15,42 +15,53 @@ class AuraDiEvent extends AthleticEvent
*/
public function get()
{
$container = new Container(new Forge(new Config()));
$container = new Container(new Factory());

$container->set('Emonkak\Di\Benchmarks\Fixtures\FooInterface', $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Foo'));
$container->params['Emonkak\Di\Benchmarks\Fixtures\Foo'] = [
'bar' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Bar'),
'baz' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Baz'),
];

$container->set('Emonkak\Di\Benchmarks\Fixtures\BarInterface', $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Bar'));
$container->params['Emonkak\Di\Benchmarks\Fixtures\Bar'] = [
'qux' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Qux'),
'quux' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Quux'),
];

$container->set('Emonkak\Di\Benchmarks\Fixtures\BazInterface', $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Baz'));
$container->params['Emonkak\Di\Benchmarks\Fixtures\Baz'] = [
'corge' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Corge'),
'grault' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Grault'),
];

$container->set('Emonkak\Di\Benchmarks\Fixtures\Qux', $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Qux'));
$container->params['Emonkak\Di\Benchmarks\Fixtures\Qux'] = [
'garply' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Garply'),
];
$container->set('Emonkak\Di\Benchmarks\Fixtures\Quux', $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Quux'));
$container->params['Emonkak\Di\Benchmarks\Fixtures\Quux'] = [
'waldo' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Waldo'),
];
$container->set('Emonkak\Di\Benchmarks\Fixtures\Corge', $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Corge'));
$container->params['Emonkak\Di\Benchmarks\Fixtures\Corge'] = [
'fred' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Fred'),
];
$container->set('Emonkak\Di\Benchmarks\Fixtures\Grault', $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Grault'));
$container->params['Emonkak\Di\Benchmarks\Fixtures\Grault'] = [
'plugh' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Plugh'),
];
$container->set('Emonkak\Di\Benchmarks\Fixtures\FooInterface', $container->lazyNew(
'Emonkak\Di\Benchmarks\Fixtures\Foo',
[
'bar' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Bar'),
'baz' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Baz'),
]
));
$container->set('Emonkak\Di\Benchmarks\Fixtures\BarInterface', $container->lazyNew(
'Emonkak\Di\Benchmarks\Fixtures\Bar',
[
'qux' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Qux'),
'quux' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Quux'),
]
));
$container->set('Emonkak\Di\Benchmarks\Fixtures\BazInterface', $container->lazyNew(
'Emonkak\Di\Benchmarks\Fixtures\Baz',
[
'corge' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Corge'),
'grault' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Grault'),
]
));
$container->set('Emonkak\Di\Benchmarks\Fixtures\Qux', $container->lazyNew(
'Emonkak\Di\Benchmarks\Fixtures\Qux',
[
'garply' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Garply'),
]
));
$container->set('Emonkak\Di\Benchmarks\Fixtures\Quux', $container->lazyNew(
'Emonkak\Di\Benchmarks\Fixtures\Quux',
[
'waldo' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Waldo'),
]
));
$container->set('Emonkak\Di\Benchmarks\Fixtures\Corge', $container->lazyNew(
'Emonkak\Di\Benchmarks\Fixtures\Corge',
[
'fred' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Fred'),
]
));
$container->set('Emonkak\Di\Benchmarks\Fixtures\Grault', $container->lazyNew(
'Emonkak\Di\Benchmarks\Fixtures\Grault',
[
'plugh' => $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Plugh'),
]
));

$container->set('Emonkak\Di\Benchmarks\Fixtures\Garply', $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Garply'));
$container->set('Emonkak\Di\Benchmarks\Fixtures\Waldo', $container->lazyNew('Emonkak\Di\Benchmarks\Fixtures\Waldo'));
Expand Down
25 changes: 25 additions & 0 deletions benchmarks/AurynDiEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Emonkak\Di\Benchmarks;

use Athletic\AthleticEvent;
use Auryn\Injector;
use Emonkak\Di\Benchmarks\Fixtures\Foo;

class AurynDiEvent extends AthleticEvent
{
/**
* @iterations 1000
*/
public function get()
{
$injector = new Injector();

$injector->alias('Emonkak\Di\Benchmarks\Fixtures\FooInterface', 'Emonkak\Di\Benchmarks\Fixtures\Foo');
$injector->alias('Emonkak\Di\Benchmarks\Fixtures\BarInterface', 'Emonkak\Di\Benchmarks\Fixtures\Bar');
$injector->alias('Emonkak\Di\Benchmarks\Fixtures\BazInterface', 'Emonkak\Di\Benchmarks\Fixtures\Baz');

$foo = $injector->make('Emonkak\Di\Benchmarks\Fixtures\FooInterface');
assert($foo instanceof Foo);
}
}
73 changes: 73 additions & 0 deletions benchmarks/BrickDiEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Emonkak\Di\Benchmarks;

use Athletic\AthleticEvent;
use Brick\Di\Container;
use Brick\Di\InjectionPolicy;
use Emonkak\Di\Benchmarks\Fixtures\Foo;

if (version_compare(PHP_VERSION, '5.5', '<')) {
class BrickDiEvent extends AthleticEvent
{
}
} else {
class BrickDiEvent extends AthleticEvent
{
/**
* @iterations 1000
*/
public function get()
{
$container = new Container(new MyPolicy());
$container->bind('Emonkak\Di\Benchmarks\Fixtures\FooInterface')->to('Emonkak\Di\Benchmarks\Fixtures\Foo');
$container->bind('Emonkak\Di\Benchmarks\Fixtures\BarInterface')->to('Emonkak\Di\Benchmarks\Fixtures\Bar');
$container->bind('Emonkak\Di\Benchmarks\Fixtures\BazInterface')->to('Emonkak\Di\Benchmarks\Fixtures\Baz');
$foo = $container->get('Emonkak\Di\Benchmarks\Fixtures\FooInterface');
assert($foo instanceof Foo);
}
}
}

class MyPolicy implements InjectionPolicy
{
/**
* {@inheritdoc}
*/
public function isClassInjected(\ReflectionClass $class)
{
return true;
}

/**
* {@inheritdoc}
*/
public function isMethodInjected(\ReflectionMethod $method)
{
return false;
}

/**
* {@inheritdoc}
*/
public function isPropertyInjected(\ReflectionProperty $property)
{
return false;
}

/**
* {@inheritdoc}
*/
public function getParameterKey(\ReflectionParameter $parameter)
{
return $parameter->getClass()->name;
}

/**
* {@inheritdoc}
*/
public function getPropertyKey(\ReflectionProperty $property)
{
return $property->getClass()->name;
}
}
23 changes: 23 additions & 0 deletions benchmarks/IlluminateContainerEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Emonkak\Di\Benchmarks;

use Athletic\AthleticEvent;
use Emonkak\Di\Benchmarks\Fixtures\Foo;
use Illuminate\Container\Container;

class IlluminateContainerEvent extends AthleticEvent
{
/**
* @iterations 1000
*/
public function get()
{
$container = new Container();
$container->bind('Emonkak\Di\Benchmarks\Fixtures\FooInterface', 'Emonkak\Di\Benchmarks\Fixtures\Foo');
$container->bind('Emonkak\Di\Benchmarks\Fixtures\BarInterface', 'Emonkak\Di\Benchmarks\Fixtures\Bar');
$container->bind('Emonkak\Di\Benchmarks\Fixtures\BazInterface', 'Emonkak\Di\Benchmarks\Fixtures\Baz');
$foo = $container->make('Emonkak\Di\Benchmarks\Fixtures\FooInterface');
assert($foo instanceof Foo);
}
}
25 changes: 25 additions & 0 deletions benchmarks/LeagueDiEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Emonkak\Di\Benchmarks;

use Athletic\AthleticEvent;
use Emonkak\Di\Benchmarks\Fixtures\Foo;
use League\Di\Container;

class LeagueDiEvent extends AthleticEvent
{
/**
* @iterations 1000
*/
public function get()
{
$container = new Container();

$container->bind('Emonkak\Di\Benchmarks\Fixtures\FooInterface', 'Emonkak\Di\Benchmarks\Fixtures\Foo');
$container->bind('Emonkak\Di\Benchmarks\Fixtures\BarInterface', 'Emonkak\Di\Benchmarks\Fixtures\Bar');
$container->bind('Emonkak\Di\Benchmarks\Fixtures\BazInterface', 'Emonkak\Di\Benchmarks\Fixtures\Baz');

$foo = $container->resolve('Emonkak\Di\Benchmarks\Fixtures\FooInterface');
assert($foo instanceof Foo);
}
}
25 changes: 16 additions & 9 deletions benchmarks/RayDiEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@

class RayDiEvent extends AthleticEvent
{
public function setUp()
{
$injector = new Injector(new MyModule());
$this->cachedInjector = serialize($injector);
}

/**
* @iterations 1000
*/
public function get()
{
$injector = Injector::create([new MyModule()]);
$injector = new Injector(new MyModule());
$foo = $injector->getInstance('Emonkak\Di\Benchmarks\Fixtures\FooInterface');
assert($foo instanceof Foo);
}
Expand All @@ -27,14 +33,7 @@ public function get()
*/
public function getWithCache()
{
$injector = new CacheInjector(
function() {
return Injector::create([new MyModule()]);
},
function() {},
'ray-di',
extension_loaded('apcu') ? new ApcuCache() : new ApcCache()
);
$injector = unserialize($this->cachedInjector);
$foo = $injector->getInstance('Emonkak\Di\Benchmarks\Fixtures\FooInterface');
assert($foo instanceof Foo);
}
Expand All @@ -47,5 +46,13 @@ protected function configure()
$this->bind('Emonkak\Di\Benchmarks\Fixtures\FooInterface')->to('Emonkak\Di\Benchmarks\Fixtures\Foo');
$this->bind('Emonkak\Di\Benchmarks\Fixtures\BarInterface')->to('Emonkak\Di\Benchmarks\Fixtures\Bar');
$this->bind('Emonkak\Di\Benchmarks\Fixtures\BazInterface')->to('Emonkak\Di\Benchmarks\Fixtures\Baz');
$this->bind('Emonkak\Di\Benchmarks\Fixtures\Qux');
$this->bind('Emonkak\Di\Benchmarks\Fixtures\Quux');
$this->bind('Emonkak\Di\Benchmarks\Fixtures\Corge');
$this->bind('Emonkak\Di\Benchmarks\Fixtures\Grault');
$this->bind('Emonkak\Di\Benchmarks\Fixtures\Garply');
$this->bind('Emonkak\Di\Benchmarks\Fixtures\Waldo');
$this->bind('Emonkak\Di\Benchmarks\Fixtures\Fred');
$this->bind('Emonkak\Di\Benchmarks\Fixtures\Plugh');
}
}
27 changes: 27 additions & 0 deletions benchmarks/ZendDiEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Emonkak\Di\Benchmarks;

use Athletic\AthleticEvent;
use Auryn\Injector;
use Emonkak\Di\Benchmarks\Fixtures\Foo;
use Zend\Di\Di;

class ZendDiEvent extends AthleticEvent
{
/**
* @iterations 1000
*/
public function get()
{
$di = new Di();

$di->instanceManager()
->addTypePreference('Emonkak\Di\Benchmarks\Fixtures\FooInterface', 'Emonkak\Di\Benchmarks\Fixtures\Foo')
->addTypePreference('Emonkak\Di\Benchmarks\Fixtures\BarInterface', 'Emonkak\Di\Benchmarks\Fixtures\Bar')
->addTypePreference('Emonkak\Di\Benchmarks\Fixtures\BazInterface', 'Emonkak\Di\Benchmarks\Fixtures\Baz');

$foo = $di->get('Emonkak\Di\Benchmarks\Fixtures\Foo');
assert($foo instanceof Foo);
}
}
15 changes: 11 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,26 @@
},
"require-dev": {
"athletic/athletic": "dev-master",
"aura/di": "~1.0",
"aura/di": "~2.0",
"brick/di": "dev-master",
"doctrine/annotations": "~1.2",
"doctrine/cache": "~1.4@dev",
"facebook/xhprof": "dev-master",
"league/di": "^1.2",
"mnapoli/php-di": "~4.4",
"nikic/php-parser": "~1.2",
"orno/cache": "~1.0",
"orno/di": "~2.3",
"phpunit/phpunit": "~4.4",
"pimple/pimple": "~3.0",
"ray/di": "~1.0",
"ray/di": "^2.2",
"rdlowrey/auryn": "^1.1",
"satooshi/php-coveralls": "dev-master",
"symfony/dependency-injection": "~2.6",
"symfony/filesystem": "~2.6",
"symfony/process": "~2.6"
"symfony/process": "~2.6",
"zendframework/zend-di": "^2.5",
"illuminate/container": "^5.1"
},
"suggest": {
"doctrine/annotations": "Used for AnnotationInjectionPolicy",
Expand All @@ -53,5 +58,7 @@
"Emonkak\\Di\\Benchmarks\\": "benchmarks/",
"Emonkak\\Di\\Tests\\": "tests/"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}

0 comments on commit 3493e4f

Please sign in to comment.