Skip to content

Instantly share code, notes, and snippets.

@g4vroche
Last active August 30, 2016 13:36
Show Gist options
  • Save g4vroche/270091bb48c5e4afd7c0d1e7ecdc6150 to your computer and use it in GitHub Desktop.
Save g4vroche/270091bb48c5e4afd7c0d1e7ecdc6150 to your computer and use it in GitHub Desktop.
PHP time debugger
<?php
$GLOBALS['timer'] = ['latest' => microtime(true), 'results' => []];
timer(__FILE__, __LINE__, "init");
function timer($file, $line, $label = false)
{
$time = microtime(true);
$GLOBALS['timer']['results'][] = [
'ellapsed' => round($time - $GLOBALS['timer']['latest'], 4),
'from_start' => round($time - $GLOBALS['timer']['results'][0]['time'],3),
'time' => $time,
'file' => $file,
'line' => $line,
'label' => $label
];
$GLOBALS['timer']['latest'] = $time;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment