Created
May 29, 2013 08:30
-
-
Save tehplague/5668799 to your computer and use it in GitHub Desktop.
Some PHP filesystem benchmarks
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 | |
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