note 116331 added to function.touch
| From: | csouth at xistins dot com | Date: | Sun, 14 Dec 2014 08:41:06 +0000 |
| Subject: | note 116331 added to function.touch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201145@lists.php.net to get a copy of this message | ||
An earlier comment referenced a code snippet that showed file_put_contents() was faster the touch
for creating files. I re-ran the same tests on PHP 5.5.9 and this seems to no longer be the case.
<?php
$startTime = microtime(true);
for($i = 0; $i < 100000; $i++)
{
file_put_contents('dir/file'.$i, '');
unlink('dir/file'.$i);
}
echo "Time: ".(microtime(true)-$startTime)."\n"; // Time: 2.6902809143066
$startTime = microtime(true);
for($i = 0; $i < 100000; $i++)
{
touch('dir/file'.$i);
unlink('dir/file'.$i);
}
echo "Time: ".(microtime(true)-$startTime)."\n"; // Time: 2.3343770503998
?>
----
Server IP: 72.52.91.14
Probable Submitter: 107.201.184.230
----
Manual Page -- http://php.net/manual/en/function.touch.php
Edit -- https://master.php.net/note/edit/116331
Del: integrated -- https://master.php.net/note/delete/116331/integrated
Del: useless -- https://master.php.net/note/delete/116331/useless
Del: bad code -- https://master.php.net/note/delete/116331/bad+code
Del: spam -- https://master.php.net/note/delete/116331/spam
Del: non-english -- https://master.php.net/note/delete/116331/non-english
Del: in docs -- https://master.php.net/note/delete/116331/in+docs
Del: other reasons-- https://master.php.net/note/delete/116331
Reject -- https://master.php.net/note/reject/116331
Search -- https://master.php.net/manage/user-notes.php