Skip to content

Instantly share code, notes, and snippets.

@masakielastic
Created July 10, 2023 12:21
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 masakielastic/1dd1dd1ddbc540ba555534e8b68e4523 to your computer and use it in GitHub Desktop.
Save masakielastic/1dd1dd1ddbc540ba555534e8b68e4523 to your computer and use it in GitHub Desktop.
<?php
function benchmark(array $callables, int $repeat = 100000): array
{
$ret = [];
$save = $repeat;
foreach ($callables as $key => $callable) {
$start = hrtime(true);
do {
$callable();
} while($repeat -= 1);
$stop = hrtime(true);
$ret[$key] = $stop - $start;
$repeat = $save;
}
return $ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment