Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active September 22, 2017 23:12
Show Gist options
  • Save vielhuber/085f4291bbcc4e8a64bbea951ff49ab9 to your computer and use it in GitHub Desktop.
Save vielhuber/085f4291bbcc4e8a64bbea951ff49ab9 to your computer and use it in GitHub Desktop.
script execution time tracking performance measuring microtime #php
<?php
function lb($message = '') {
if(!isset($GLOBALS['performance'])) { $GLOBALS['performance'] = []; }
$GLOBALS['performance'][] = ['time' => microtime(true), 'message' => $message];
}
function le() {
echo 'script '.$GLOBALS['performance'][count($GLOBALS['performance'])-1]['message'].' execution time: '.number_format((microtime(true)-$GLOBALS['performance'][count($GLOBALS['performance'])-1]['time']),5). ' seconds'.PHP_EOL;
unset($GLOBALS['performance'][count($GLOBALS['performance'])-1]);
$GLOBALS['performance'] = array_values($GLOBALS['performance']);
}
lb('task');
for($i = 0; $i < 10000; $i++) {
lb('childtask');
for($y = 0; $y < 100; $y++) { }
le();
}
le();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment