Created
March 14, 2016 14:37
-
-
Save kuwa72/a69b0d1807727ff7eeb6 to your computer and use it in GitHub Desktop.
Tiny IO benchmark in PHP.
This file contains hidden or 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 | |
for ($j = 0; $j < 100; $j++) { | |
$time = microtime(true); | |
for ($i = 0; $i < 1000; $i++) { | |
$fn = sprintf("%04d", $i); | |
file_put_contents($fn . ".spf", "asdfasdfasdfasdf"); | |
} | |
echo (microtime(true) - $time); | |
echo ","; | |
$files = glob("*.spf"); | |
$time = microtime(true); | |
foreach ($files as $fn) { | |
stat($fn); | |
} | |
echo (microtime(true) - $time); | |
echo ","; | |
$time = microtime(true); | |
foreach ($files as $fn) { | |
file_get_contents($fn); | |
} | |
echo (microtime(true) - $time); | |
echo ","; | |
$time = microtime(true); | |
foreach ($files as $fn) { | |
unlink($fn); | |
} | |
echo (microtime(true) - $time); | |
echo "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment