Skip to content

Instantly share code, notes, and snippets.

@wonzbak
Last active January 13, 2020 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wonzbak/a727ea7a520e67cd04d093b7e2e5abdd to your computer and use it in GitHub Desktop.
Save wonzbak/a727ea7a520e67cd04d093b7e2e5abdd to your computer and use it in GitHub Desktop.
Get time elapse of a function
<?php
function timeIt(
callable $callable,
array $params = [],
int $maxLoop = 1000,
bool $returnValue = false
) {
$start = microtime(true);
for ($i = 0; $i < $maxLoop; $i++) {
$callable(...$params);
}
$timeElapsed = microtime(true) - $start;
$timeElapsed = sprintf('%f', $timeElapsed);
if ($returnValue) {
return $timeElapsed;
} else {
echo $timeElapsed . " s \n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment