We'll overload the run method of Benchmark_Iterate to allow for passing a data generation function.
<?php
require_once "Benchmark/Iterate.php";
class Benchmark_RandomData
extends Benchmark_Iterate
{
function run() {
$arguments = func_get_args();
$iterations = array_shift($arguments);
$function_name = array_shift($arguments);
$data_func = array_shift($arguments);
for ($i = 1; $i <= $iterations; $i++) {
$data = call_user_func_array($data_func,
$arguments);
$this->setMarker('start_' . $i);
call_user_func_array($function_name,
$data);
$this->setMarker('end_' . $i);
}
}
}
?>
<?php
require_once "Benchmark_RandomData.inc";
foreach(array(10, 100, 1000) as $size) {
print "Array size $size\n";
foreach(array('max', 'my_max') as $func) {
$b = new Benchmark_RandomData;
$b->run(100, $func,
'create_random_array', $size);
$result = $b->get();
print "$func\t";
printf("System + User Time: %1.6f\n",
$result['mean']);
}
}
?>