Last active
January 13, 2020 10:16
-
-
Save wonzbak/a727ea7a520e67cd04d093b7e2e5abdd to your computer and use it in GitHub Desktop.
Get time elapse of a function
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 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