TRPB / php-dependency-injection-benchmarks

Benchmarks for several popular PHP DI Containers
38 stars 18 forks source link

test3.php #19

Open mindplay-dk opened 9 years ago

mindplay-dk commented 9 years ago

I don't think "test3.php" benchmarks what you think it does - at least, after looking at implementations for pimple and php-di, in both cases, as far as I can tell, you're not benchmarking the time taken to create the object graph at all.

For instance, here in php-di/test3.php you've already resolved the object graph when you triggered the autoloader. Since you continue benchmarking the same container, the object graph has already been resolved, so all it's doing in the loop, is a key lookup.

pimple/test3.php is a different benchmark entirely - here, you're actually creating a new container every time, inside the loop, triggering an actual resolve of the object graph.

league/test3.php also appears to resolve the object graph outside of the loop.

I'm trying to write the benchmark for my own container, but how is it supposed to work? Which of the benchmarks should I be using as point of reference?

TRPB commented 9 years ago

Well spotted, I think you're right about pimple and I'll update it.

However, the test itself is correct, it should be creating a new object graph on each iteration. So for example, looking at League

https://github.com/TomBZombie/php-dependency-injection-benchmarks/blob/master/league/test3.php#L11

$one = $container->get('J');
$two = $container->get('J');

var_dump($one === $two) should evaluate to false, similarly, $one->i === $two->i should evaluate to false.

edit: If all php-di is doing is a key lookup it's doing it incredibly inefficiently!

mnapoli commented 9 years ago

For the PHP-DI test, see the config file -> it will return a new instance every time so the behavior should be inline with the other tests.