Skip to content

Instantly share code, notes, and snippets.

@rvanvelzen
Created January 25, 2012 14:41
Show Gist options
  • Save rvanvelzen/1676570 to your computer and use it in GitHub Desktop.
Save rvanvelzen/1676570 to your computer and use it in GitHub Desktop.
Simple benchmark function for PHP >5.3
<?php
/**
* Very simplistic timing
*
* @param string $name Name of the current timing
* @param callback $what Function pointer to be executed
* @param int $times Number of times the function will be executed
*/
function bench($name, $what, $times = 1000) {
$start = microtime(true);
for ($i = 0; $i < $times; ++$i) {
$what();
}
$end = microtime(true);
echo $name . ': ' . ($end - $start) . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment