Last active
October 10, 2018 06:41
-
-
Save JanTvrdik/cf67f2837e4eda8f947edf297b5a5015 to your computer and use it in GitHub Desktop.
PHP quick benchmark skeleton
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 | |
$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