Last active
September 22, 2017 23:12
-
-
Save vielhuber/085f4291bbcc4e8a64bbea951ff49ab9 to your computer and use it in GitHub Desktop.
script execution time tracking performance measuring microtime #php
This file contains hidden or 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 | |
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