1
0
mirror of synced 2024-12-15 07:36:03 +03:00
doctrine2/benchmark/mixin.php

70 lines
1.3 KiB
PHP
Raw Normal View History

2007-09-01 03:20:02 +04:00
<?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";