Re: Re: File::readAll()
| From: | Tomas V.V.Cox | Date: | Thu, 01 Aug 2002 10:41:34 +0000 |
| Subject: | Re: Re: File::readAll() | ||
| References: | 1 2 3 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-8119@lists.php.net to get a copy of this message | ||
Olivier Vanhoucke wrote:
>
> > I think the opposite :-)
>
> really ?
>
> $tmp = '';
> $fp = fopen($filename, 'r');
> while (!feof($fp) {
> $tmp .= fget($fp, 1024);
> }
> fclose($fp);
>
> (or something like that) will be faster than
>
> $tmp = implode('', file($filename));
>
> I'm not convinced !
See that then:
f.php
-----
<?php
$file = $argv[1];
require 'Benchmark/Timer.php';
$bench = &new Benchmark_Timer(true);
($fd = fopen($file, 'r')) or die('no file');
$data = '';
while ($tmp = fread($fd, 1024)) {
$data .= $tmp;
}
fclose($fd);
$bench->setMarker('fread');
$data = implode('', file($file));
?>
# du -h f.php
1.0k f.php
# php -f f.php -- f.php
-------------------------------------------------------------
marker time index ex time perct
-------------------------------------------------------------
Start 1028198257.42681000 - 0.00%
-------------------------------------------------------------
fread 1028198257.42722700 0.000417 53.26%
-------------------------------------------------------------
Stop 1028198257.42759300 0.000366 46.74%
-------------------------------------------------------------
total - 0.000783 100.00%
-------------------------------------------------------------
# du -h squirrelmail-1.2.7.tar.bz2
1.2M squirrelmail-1.2.7.tar.bz2
# php -f f.php -- squirrelmail-1.2.7.tar.bz2
-------------------------------------------------------------
marker time index ex time perct
-------------------------------------------------------------
Start 1028198361.31103600 - 0.00%
-------------------------------------------------------------
fread 1028198361.33557000 0.024534 28.68%
-------------------------------------------------------------
Stop 1028198361.39657800 0.061008 71.32%
-------------------------------------------------------------
total - 0.085542 100.00%
-------------------------------------------------------------
Tomas V.V.Cox