Skip to content

Instantly share code, notes, and snippets.

@nicklasos
Last active January 1, 2016 18:09
Show Gist options
  • Save nicklasos/8182217 to your computer and use it in GitHub Desktop.
Save nicklasos/8182217 to your computer and use it in GitHub Desktop.
Time elapsed
<?php
/**
* Inline profiler :)
*
* $time = s();
* for ($i = 0; $i < 100000; $i++) {
* $j = $i + 1;
* }
* s($time);
*
* @param bool|int $time
* @return mixed
*/
function s($time = false)
{
if ($time) {
echo number_format(microtime(true) - $time, 2) . 's';
} else {
return microtime(true);
}
}
$t = s();
for ($i = 0; $i < 100000; $i++) {
$j = $i + 1;
}
s($t);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment