Created
October 7, 2019 08:44
-
-
Save andrey-legayev/079652e03b9fd5d87740c706ad91035a to your computer and use it in GitHub Desktop.
PHP benchmark: array_flip() performance dependent on array size
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 test($size) | |
{ | |
// prepare arrays | |
$plain = []; | |
for ($i = 0; $i < $size; $i++) { | |
$value = rand(); | |
array_push($plain, $value); | |
} | |
// run tests | |
$t1 = microtime(true); | |
$x = array_flip($plain); | |
$t1 = microtime(true) - $t1; | |
// echo results as CSV | |
printf("%s, %d, %f\n", phpversion(), $size, $t1); | |
} | |
echo "# PHP Version, Array Size, array_flip()\n"; | |
for ($i = 1; $i <= 100000; $i = $i * 10) { | |
test($i); | |
} |
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
#!/bin/bash | |
for ver in 7.0 7.1 7.2 7.3; do | |
echo "# running tests for version $ver" | |
image=php:$ver-cli | |
docker run --rm -v "$PWD":/src $image \ | |
bash -c "php /src/perf-test.php" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My results:
X Y Scatter Plot: