Skip to content

Instantly share code, notes, and snippets.

@tehplague
Created May 29, 2013 08:30
Show Gist options
  • Save tehplague/5668799 to your computer and use it in GitHub Desktop.
Save tehplague/5668799 to your computer and use it in GitHub Desktop.
Some PHP filesystem benchmarks
<?php
clearstatcache();
$t1 = (double)microtime(true);
for ($i = 0; $i < 100000; ++$i) {
$result = file_exists('/tmp') && is_writable('/tmp');
}
$t2 = (double)microtime(true);
echo sprintf('file_exists + is_writable: %f' . PHP_EOL, ($t2 - $t1));
clearstatcache();
$t1 = (double)microtime(true);
for ($i = 0; $i < 100000; ++$i) {
$result = is_dir('/tmp') && is_writable('/tmp');
}
$t2 = (double)microtime(true);
echo sprintf('is_dir + is_writable: %f' . PHP_EOL, ($t2 - $t1));
clearstatcache();
$t1 = (double)microtime(true);
for ($i = 0; $i < 100000; ++$i) {
$stat = stat('/tmp');
$result = (($stat['mode'] & 040200) > 0); // S_IFDIR | S_IWUSR (http://man7.org/linux/man-pages/man2/stat.2.html)
}
$t2 = (double)microtime(true);
echo sprintf('stat: %f' . PHP_EOL, ($t2 - $t1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment