-
-
Save lisachenko/22fba9ec192b09056ceb to your computer and use it in GitHub Desktop.
Performance test of Go! AOP library and PHP-AOP extension (0.2b)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Should be in the demos directory of Go! AOP PHP and requires PHP>=5.4 | |
include __DIR__ . './autoload.php'; | |
for ($j=0; $j<pow(3,0); $j++) { | |
aop_add_before('*Example\General->*()', function ($invocation) { | |
}); | |
} | |
$time = microtime(true); | |
$example = new Example\General('test'); | |
for ($i=0; $i<1e4; $i++) { | |
$example->noop(); // empty method | |
} | |
$end = microtime(true); | |
echo "Took: ", number_format(($end-$time) * 1e3, 3), " ms and ", number_format(memory_get_peak_usage(true) / 1024 / 1024, 2), "Mb"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Should be in the demos directory of Go! AOP PHP and requires PHP>=5.4 | |
include __DIR__ . './autoload_aspect.php'; | |
class Aspect implements Go\Aop\Aspect | |
{ | |
public function beforeAdvice($invocation) | |
{ | |
} | |
} | |
$aspectKernel = \Aspect\AwesomeAspectKernel::getInstance(); | |
$container = $aspectKernel->getContainer(); | |
$aspect = new Aspect; | |
$closure = (new ReflectionMethod('Aspect', 'beforeAdvice'))->getClosure($aspect); | |
$container->registerAspect($aspect); | |
$advisor = new Go\Aop\Support\DefaultPointcutAdvisor( | |
new Go\Aop\Pointcut\TrueMethodPointcut(), | |
new Go\Aop\Framework\MethodBeforeInterceptor($closure) | |
); | |
for ($j=0; $j<pow(3,0); $j++) { | |
$container->registerAdvisor($advisor, 'advisor' . $j); | |
} | |
$time = microtime(true); | |
$example = new Example\General('test'); | |
for ($i=0; $i<1e4; $i++) { | |
$example->noop(); // empty method | |
} | |
$end = microtime(true); | |
echo "Took: ", number_format(($end-$time) * 1e3, 3), " ms and ", number_format(memory_get_peak_usage(true) / 1024 / 1024, 2), "Mb"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original time without AOP: 3.0ms. | |
APC is enabled (apc.stat = On, apc.canonicalize = Off, apc.stat_ctime = Off) | |
Measuring method invocation time for 1e4 iterations. | |
Num of advices: 1 3 9 27 81 243 729 2187 | |
AOP-PHP 25ms 61ms 153ms 420ms Out of Out of Out of Out of | |
(match) 3.5Mb 7.25Mb 20.5Mb 62.75Mb mem mem mem mem | |
AOP-PHP 3.5ms 3.9ms 5ms 8.2ms 19ms 61ms 180ms 530ms | |
(non-match) 0.25Mb 0.25Mb 0.25Mb 0.25Mb 0.25Mb 0.25Mb 0.75Mb 1.25Mb | |
Go! AOP 90ms 178ms 385ms 1096ms 3300ms 10500ms Out of Out of | |
(match) 0.5Mb 0.5Mb 0.5Mb 0.5Mb 0.75Mb 1Mb time time | |
Go! AOP 3.5ms 3.5ms 3.5ms 3.5ms 3.5ms 3.5ms 3.5ms 3.5ms | |
(non-match) 0.5Mb 0.5Mb 0.5Mb 0.5Mb 0.5Mb 0.5Mb 0.5Mb 0.75Mb | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment