Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@luckyshot
Last active April 4, 2021 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save luckyshot/43327121c67c47947fcb9efde318cb97 to your computer and use it in GitHub Desktop.
Save luckyshot/43327121c67c47947fcb9efde318cb97 to your computer and use it in GitHub Desktop.
Simple PHP benchmarking script
<?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