Skip to content

Instantly share code, notes, and snippets.

@rivetmichael
Created September 15, 2015 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rivetmichael/b31505d7b8f0dc36bad9 to your computer and use it in GitHub Desktop.
Save rivetmichael/b31505d7b8f0dc36bad9 to your computer and use it in GitHub Desktop.
A simple comparison between reflection instantiation and new object instantiation
<?php
require __DIR__ . '/app/bootstrap.php';
$config = [
'drivers' => [
[
'output' => [
'type' => 'html',
'thresholds' => [
'sum' => 0
]
]
]
],
'driverFactory'
];
Magento\Framework\Profiler::applyConfig($config, BP);
Magento\Framework\Profiler::enable();
for ($cpt = 0;$cpt < 1000000; $cpt++) {
Magento\Framework\Profiler::start('__reflection__');
$r = new \ReflectionClass('Pulsestorm\TutorialProxy1\Model\Message');
Magento\Framework\Profiler::stop('__reflection__');
unset($r);
}
for ($cpt = 0;$cpt < 1000000; $cpt++) {
Magento\Framework\Profiler::start('__plain old new__');
$r = new Pulsestorm\TutorialProxy1\Model\Message;
Magento\Framework\Profiler::stop('__plain old new__');
unset($r);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment