- microtime: documentation ( source)
- sprintf: documentation ( source)
<?php
class Route {
protected $path;
public function __construct($path) {
$this->path = $path;
}
}
$routes = array();
$start = microtime(true);
for($x = 0; $x < 100; $x++) {
$routes[] = new Route("/a");
}
echo sprintf("Class: Took %f ms\n", (microtime(true) - $start));
$routes2 = array();
$start = microtime(true);
for($x = 0; $x < 100; $x++) {
$routes2[] = (object)array(
'path' => '/a'
);
}
echo sprintf("stdClass: Took %f ms\n", (microtime(true) - $start));
$routes3 = array();
$start = microtime(true);
for($x = 0; $x < 100; $x++) {
$routes3[] = array(
'path' => '/a'
);
}
echo sprintf("array: Took %f ms\n", (microtime(true) - $start));