Created
November 7, 2017 06:16
-
-
Save wilon/89b534696e1335052f8a7fe7c668597b to your computer and use it in GitHub Desktop.
Count php script run time.
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 | |
/** | |
* PHP time debug | |
* @param string $mark | |
* @param string $separate | |
* @return array | |
*/ | |
function timeDebug($mark, $echo = true, $separate) | |
{ | |
global $timeDebug; | |
$separate = $separate ?: (PHP_SAPI == 'cli' ? PHP_EOL : '<br>'); | |
$mt = microtime(); | |
if (!$mark) $mark = 'timeDebug'; | |
$timeDebug[$mark][] = (float) (substr((string) $mt, 17) . substr((string) $mt, 1, 6)); | |
$arr = $timeDebug[$mark]; | |
$endKey = count($arr) - 1; | |
if (array_key_exists($endKey - 1, $arr)) { | |
$timeDiff = sprintf('%.5f', $arr[$endKey] - $arr[$endKey - 1]); | |
$separate = ' >> ' . $timeDiff . 's' . $separate; | |
$markDiff = $endKey . '_' . $endKey - 1; | |
$markDiffKey = $mark . '_diff'; | |
$timeDebug[$markDiffKey][$markDiff] = $timeDiff; | |
} | |
if ($echo) { | |
echo $mark, ' ', date('Y-m-d H:i:s') . substr((string) microtime(), 1, 6), $separate; | |
} | |
return $timeDebug; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use?