Skip to content

Instantly share code, notes, and snippets.

@kuwa72
Created March 14, 2016 14:37
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 kuwa72/a69b0d1807727ff7eeb6 to your computer and use it in GitHub Desktop.
Save kuwa72/a69b0d1807727ff7eeb6 to your computer and use it in GitHub Desktop.
Tiny IO benchmark in PHP.
<?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