Skip to content

Instantly share code, notes, and snippets.

@AlexVanderbist
Created March 16, 2023 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexVanderbist/2f8e897c878c44cc88579a4a4a357b09 to your computer and use it in GitHub Desktop.
Save AlexVanderbist/2f8e897c878c44cc88579a4a4a357b09 to your computer and use it in GitHub Desktop.
EZ measure
function measure(string $label = 'default') {
static $starts;
if ($starts[$label]) {
dump($label . ' took '. (microtime(true) - $starts[$label]) . ' seconds');
}
$starts[$label] = microtime(true);
}
measure();
sleep(1);
measure(); // "default took 1 seconds"
measure('total');
sleep(1);
measure('sleep');
sleep(2);
measure('sleep'); // "sleep took 2 seconds"
measure('total'); // "total took 3 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment