1
0
mirror of synced 2024-12-13 22:56:04 +03:00
doctrine2/benchmark/mixin.php
2007-08-31 23:20:02 +00:00

70 lines
1.3 KiB
PHP

<?php
function mixin($tpl, $method = null)
{
static $_map;
if ( ! isset($_map[$tpl . $method])) {
if ($method === null) {
$refl = new ReflectionFunction($tpl);
} else {
$refl = new ReflectionMethod($tpl, $method);
}
$lines = file($refl->getFileName());
$start = $refl->getStartLine();
$end = $refl->getEndLine();
$ret = array_slice($lines, $start, ($end - $start));
$code = trim(trim(implode(' ', $ret)), '{}');
$_map[$tpl . $method] = $code;
} else {
$code = $_map[$tpl . $method];
}
eval($code);
}
function someCode() {
$a = 10;
}
class Template
{
public function exec()
{
$a = 10;
}
}
print "<pre>MIXIN BENCHMARK \n";
$timepoint = microtime(true);
$i = 500;
while ($i--) {
mixin('someCode');
}
print 'EXECUTED 500 CODE BLOCKS : ' . (microtime(true) - $timepoint) . "\n";
$timepoint = microtime(true);
$i = 500;
while ($i--) {
someCode();
}
print 'EXECUTED 500 DIRECT FUNCTION CALLS : ' . (microtime(true) - $timepoint) . "\n";
$timepoint = microtime(true);
$i = 500;
while ($i--) {
eval('$a = 10;');
}
print 'EXECUTED 500 DIRECT EVAL CALLS : ' . (microtime(true) - $timepoint) . "\n";