|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-07-13 20:13 UTC] video dot ice dot power at seznam dot cz
Description:
------------
file_exists() is 30 times slover than is_dir()
Test script:
---------------
for ($i = 0; $i < 1000; $i++) { is_dir('some path to directory'); } // 0.5ms
for ($i = 0; $i < 1000; $i++) { file_exists('some path to directory'); } // 15 ms
Expected result:
----------------
The file_exists method should run in about the same time as the is_dir method does.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 08:00:01 2025 UTC |
<?php $t0 = hrtime(true); for ($i = 0; $i < 1000; $i++) { is_dir(__DIR__); } $t1 = hrtime(true); for ($i = 0; $i < 1000; $i++) { file_exists(__DIR__); } $t2 = hrtime(true); printf("is_dir took %f ms\n", ($t1 - $t0)/10e6); printf("file_exists took %f ms\n", ($t2 - $t1)/10e6); outputs for me something like: is_dir took 0.051130 ms file_exists took 3.395850 ms