- microtime: documentation ( source)
- printf: documentation ( source)
<?php
class EmptySetter {
public function __set($name, $value) {}
}
class NonEmptySetter {
public function __set($name, $value) {
$this->{$name} = $value;
}
}
function benchmark($class_name) {
$start_time = microtime(TRUE);
for ($i = 0; $i < 1; $i++) {
$obj = new $class_name();
$obj->foo = 42;
echo $obj->foo;
}
return microtime(TRUE) - $start_time;
}
printf("EmptySetter: %.2f seconds\n", benchmark('EmptySetter'));