Skip to content

Instantly share code, notes, and snippets.

@JanTvrdik
Last active October 10, 2018 06:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JanTvrdik/cf67f2837e4eda8f947edf297b5a5015 to your computer and use it in GitHub Desktop.
Save JanTvrdik/cf67f2837e4eda8f947edf297b5a5015 to your computer and use it in GitHub Desktop.
PHP quick benchmark skeleton
<?php
$runCount = 1000;
$dataSets = [
'setA' => [$runCount, 123],
];
$tests = [
'testA' => function ($count, $n) {
while ($count--) {
}
},
];
$padLength = max(array_map('strlen', array_keys($dataSets))) + 2;
foreach ($tests as $testName => $test) {
printf("Test %s:\n", $testName);
foreach ($dataSets as $dataSetName => $dataSet) {
$time = -microtime(TRUE);
$test(...$dataSet);
$time += microtime(TRUE);
printf(" %s%5.0f ms\n", str_pad($dataSetName, $padLength), $time * 1e3);
}
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment