PHP中创建空文件的代码[file_put_contents vs touch]

 更新时间:2012年01月20日 13:11:54   作者:  
php中用file_put_contents比touch快,大约两倍左右。
I has passed a small test to check which function is faster to create a new file.

file_put_contents vs touch
复制代码 代码如下:

<?php
for($i = ; $i < 100; $i++)
{
file_put_contents('dir/file'.$i, '');
}
?>

Average time: 0,1145s
复制代码 代码如下:

<?php
for($i = ; $i < 100; $i++)
{
touch('dir/file'.$i);
}
?>

Average time: 0,2322s

所以,file_put_contentstouch快,大约两倍。

相关文章

最新评论