Skip to content

Instantly share code, notes, and snippets.

@SteGriff
Created September 28, 2015 11:05
Show Gist options
  • Save SteGriff/eb3422549851bc0496ac to your computer and use it in GitHub Desktop.
Save SteGriff/eb3422549851bc0496ac to your computer and use it in GitHub Desktop.
Micro-benchmark timing with PHP
<?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