黄聪:is_file和file_exists效率比较
2017-10-27 17:34
393 查看
目前在弄文件缓存的时候用到了判定文件存在与否,is_file()还是file_exists()呢?is_file和file_exists两者效率比较起来,谁的运行速度更快呢?还是做个测试吧:
运行1万次:
is_file–>0.0067121982574463
file_exits–>0.11532402038574
运行10万次:
is_file–>0.069056034088135
file_exits–>1.1521670818329
当运行100万次:
is_file–>0.6924250125885
file_exits–>11.497637987137
当文件不存在时:
运行1万次:
is_file–>0.72184419631958
file_exits–>0.71474003791809
运行10万次:
is_file–>7.1535291671753
file_exits–>7.0911409854889
当运行100万次:
is_file–>72.042867183685
file_exits–>71.789203166962
超过1分钟了,别忘了在php第一行加句:
set_time_limit(120);//时间限制120秒
* 如果要判断目录是否存在,请优先考虑函数 is_dir(directory)
* 如果要判断文件是否存在,请优先考虑函数 is_file(filepath)
is_dir–>0.0058560371398926
file_exits–>0.11063098907471
当目录不存在时,运行1万次
is_dir–>0.7159481048584
file_exits–>0.71305584907532
测试结果:
当文件存在时:运行1万次:
is_file–>0.0067121982574463
file_exits–>0.11532402038574
运行10万次:
is_file–>0.069056034088135
file_exits–>1.1521670818329
当运行100万次:
is_file–>0.6924250125885
file_exits–>11.497637987137
当文件不存在时:
运行1万次:
is_file–>0.72184419631958
file_exits–>0.71474003791809
运行10万次:
is_file–>7.1535291671753
file_exits–>7.0911409854889
当运行100万次:
is_file–>72.042867183685
file_exits–>71.789203166962
超过1分钟了,别忘了在php第一行加句:
set_time_limit(120);//时间限制120秒
结论:
is_file()和file_exists()效率比较,结果当文件存在时,is_file函数比file_exists函数速度快14倍,当文件不存在时,两者速度相当。同理,当文件目录存在时,is_dir()比file_exists()快18倍。不存在时两者效率相当。PHP的file_exists = is_dir + is_file。* 如果要判断目录是否存在,请优先考虑函数 is_dir(directory)
* 如果要判断文件是否存在,请优先考虑函数 is_file(filepath)
is_dir()对比file_exists()测试结果:
当目录存在时,运行1万次is_dir–>0.0058560371398926
file_exits–>0.11063098907471
当目录不存在时,运行1万次
is_dir–>0.7159481048584
file_exits–>0.71305584907532
相关文章推荐
- is_file、is_dir和file_exists用途和效率比较
- PHP中file_exists与is_file、is_dir的区别,以及执行效率的比较
- is_file和file_exists效率比较
- is_file和file_exists效率比较
- PHP中file_exists与is_file、is_dir的区别,以及执行效率的比较
- PHP中file_exists与is_file、is_dir的区别,以及执行效率的比较
- PHP中file_exists与is_file、is_dir的区别,以及执行效率的比较
- is_file、is_dir和file_exists用途和效率比较
- PHP中file_exists与is_file、is_dir的区别,以及执行效率的比较 转自#冰雪傲骨#
- is_file 与 file_exists 的区别
- File.exists()判断文件是否存在,File.isDirectory()判断目录是否存在
- SQL里的EXISTS与in、not exists与not in 效率比较和使用
- PHP中file_exists与is_file,is_dir的区别
- PHP中file_exists与is_file,is_dir的区别介绍
- php判断文件存在是用file_exists 还是 is_file
- PHP中file_exists与is_file,is_dir的区别介绍
- PHP学习之路之PHP文件上传需要考虑的问题以及解决方法($_FILES,$_SERVER,substr,strrpos,file_exists,move_uploaded_file,is_uploaded_file,mkdir)
- fsockopen/curl/file_get_contents效率比较
- SQL里的EXISTS与in、not exists与not in 效率比较和使用(转)
- java.io.file.isfile与exists区别