Skip to content

Instantly share code, notes, and snippets.

@speedmax
Created February 25, 2009 23:28
Show Gist options
  • Save speedmax/70523 to your computer and use it in GitHub Desktop.
Save speedmax/70523 to your computer and use it in GitHub Desktop.
<?php
require_once 'Benchmark/Timer.php';
class Benchmark {
var $iteration = 100;
function setup() {
}
final static function report() {
$benches = array_filter(get_declared_classes(),
create_function('$class','
return is_subclass_of($class, "Benchmark") && true;
')
);
$results = array();
foreach ($benches as $bench) {
$methods = array_filter(get_class_methods($bench),
create_function('$m','return strpos($m, "bench") === 0;')
);
$results[$bench] = array();
$runner = new $bench;
$runner->setup();
$bm = new Benchmark_Timer(true);
foreach($methods as $method) {
foreach(range(1, $runner->iteration) as $i) {
$runner->$method();
}
$desc = strtr($method, array('bench' => '', '_' => ' '));
$bm->setMarker($desc);
}
$results[$bench] = $bm->display();
}
return $results;
}
}
?>
<?php
require 'context.php';
require 'benchmark.php';
class BenchContext extends Benchmark {
var $iteration = 10000;
function setup() {
$person = array(
'name'=>'taylor',
'age'=>18,
'hobbies'=>array('watch tv','swimming', 'walking', 'kick boxing','watch tv','swimming', 'walking', 'kick boxing','watch tv','swimming', 'walking', 'kick boxing','watch tv','swimming', 'walking', 'kick boxing','watch tv','swimming', 'walking', 'kick boxing')
);
$this->context = new H2o_Context(compact('person'));
}
function bench_resolve_associative_array() {
$this->context->resolve('person.name');
}
function bench_resolve_array_shortcut_first() {
$this->context->resolve('person.hobbies.first');
}
function bench_resolve_array_shortcut_last() {
$this->context->resolve('person.hobbies.last');
}
function bench_resolve_array_shortcut_length() {
$this->context->resolve('person.hobbies.length');
}
function bench_undefined_variable() {
$this->context->resolve('person.undefined');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment