Skip to content

Instantly share code, notes, and snippets.

@davedevelopment
Forked from igorw/RESULTS
Last active December 15, 2015 22:49
Show Gist options
  • Save davedevelopment/5335699 to your computer and use it in GitHub Desktop.
Save davedevelopment/5335699 to your computer and use it in GitHub Desktop.
{
"require": {
"pimple/pimple": "1.0.*",
"symfony/dependency-injection": "2.2.*"
}
}
Pimple
273K
2153K
0.009068s
DependencyInjection
275K
2903K
0.051517s
DependencyInjection (dumped)
2041K
2413K
0.006198s
#!/bin/bash
FLAGS="-d xdebug.max_nesting_level=300"
RUNS=1000
echo "Pimple"
php $FLAGS test-pimple.php $RUNS
echo "DependencyInjection"
php $FLAGS test-di.php $RUNS
echo "DependencyInjection (dumped)"
php $FLAGS test-di-dumped.php $RUNS
<?php
class Service {
private $service;
private $param;
public function __construct(Service $service, $param)
{
$this->service = $service;
$this->param = $param;
}
}
class NullService extends Service {
public function __construct() {}
}
<?php
require 'vendor/autoload.php';
require 'service.php';
require 'dumped.php';
$runs = $argv[1];
$start = microtime(true);
echo intval(memory_get_usage() / 1024).'K'."\n";
$container = new ProjectServiceContainer();
foreach (range(1, $runs) as $i) {
$serv = $container->get("service_".$i);
}
echo intval(memory_get_usage() / 1024).'K'."\n";
echo round(microtime(true) - $start, 6).'s'."\n";
<?php
require 'vendor/autoload.php';
require 'service.php';
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
$runs = $argv[1];
$start = microtime(true);
echo intval(memory_get_usage() / 1024).'K'."\n";
$container = new ContainerBuilder();
$container->setParameter('param', 'foo');
$container
->register('service_1', 'NullService');
foreach (range(2, $runs) as $i) {
$container
->register('service_'.$i, 'Service')
->addArgument(new Reference('service_'.($i - 1)))
->addArgument('%param%');
}
foreach (range(1, $runs) as $i) {
$serv = $container->get("service_".$i);
}
echo intval(memory_get_usage() / 1024).'K'."\n";
echo round(microtime(true) - $start, 6).'s'."\n";
use Symfony\Component\DependencyInjection\Compiler\Compiler;
$compiler = new Compiler();
$compiler->compile($container);
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
$dumper = new PhpDumper($container);
file_put_contents('dumped.php', $dumper->dump());
<?php
require 'vendor/autoload.php';
require 'service.php';
$runs = $argv[1];
$start = microtime(true);
echo intval(memory_get_usage() / 1024).'K'."\n";
$container = new Pimple();
$container['param'] = 'foo';
$container['service_0'] = new NullService;
foreach (range(1, $runs) as $i) {
$container['service_'.$i] = $container->share(function ($container) use ($i) {
return new Service($container['service_'.($i - 1)], $container['param']);
});
}
foreach (range(1, $runs) as $i) {
$serv = $container['service_'.$i];
}
echo intval(memory_get_usage() / 1024).'K'."\n";
echo round(microtime(true) - $start, 6).'s'."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment