Last active
April 4, 2021 14:04
-
-
Save luckyshot/43327121c67c47947fcb9efde318cb97 to your computer and use it in GitHub Desktop.
Simple PHP benchmarking script
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 | |
$benchmark_time = microtime(1); | |
$benchmark_string = ''; | |
function benchmark( $string = ''){ | |
global $benchmark_time, $benchmark_string; | |
$return = sprintf('%f', microtime(1) - $benchmark_time) . 's ' . $benchmark_string; | |
$benchmark_time = microtime(1); | |
$benchmark_string = $string; | |
return $return; | |
} | |
echo benchmark('START').PHP_EOL; | |
echo benchmark('Sleep one second').PHP_EOL; | |
sleep(1); | |
echo benchmark('Sleep two seconds').PHP_EOL; | |
sleep(2); | |
echo benchmark('END').PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment