Created
January 25, 2012 14:41
-
-
Save rvanvelzen/1676570 to your computer and use it in GitHub Desktop.
Simple benchmark function for PHP >5.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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