Created
September 28, 2015 11:05
-
-
Save SteGriff/eb3422549851bc0496ac to your computer and use it in GitHub Desktop.
Micro-benchmark timing with PHP
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 | |
function startTiming(){ | |
$GLOBALS['start'] = microtime(true); | |
} | |
function stopTiming(){ | |
$duration = (microtime(true) - $GLOBALS['start']); | |
return $duration; | |
} | |
function initLapTiming() | |
{ | |
$GLOBALS['timings'] = "\r\n ----- NEW SESSION ----- \r\n" . date('c') . "\r\n"; | |
startTiming(); | |
} | |
function lapTiming($label) | |
{ | |
$GLOBALS['timings'] .= "\r\n$label : " . stopTiming(); | |
startTiming(); | |
} | |
function logLaps() | |
{ | |
file_put_contents('log.txt', $GLOBALS['timings'], FILE_APPEND); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment