Re: Too slow execution time.
| From: | Zeev Suraski | Date: | Sat, 02 Oct 1999 02:52:51 +0000 |
| Subject: | Re: Too slow execution time. | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-11424@lists.php.net to get a copy of this message | ||
On Sat, 2 Oct 1999, KIM Hiongun wrote:
>
> I'm using PHP3.0.7.
>
> I have a text file of lines that end with "QR=....",
> and I want to extract the tailing part of each line.
> My first PHP code was...
>
> $lines = file($filename);
> for ($i = 0; $i < count($lines); $i++) {
> $query = strstr($line[$i], "QR=");
> printf("$query\n");
> }
>
> Alas however, my code run out execution timeout error.
> (The text file is about 60,000 lines. The code dies
> at about 3,000'th line, and the lifetime was 30 seconds.)
>
> The same thing I did with a Perl code, that seems to
> be very similar...
>
> open(F, "< $filename");
> @lines = <F>; # read in each lines into an array
> close(F);
>
> foreach $line (@lines) {
> if ($line =~ m/QR=(.*)/) {
> $query = $1;
> print "$query\n";
> }
> }
>
> This Perl code does all the processing in 1.2 seconds.
> What the hell... Seems to me that Perl's just-in-time
> compiling works very effectively.
>
> Seems to me that "implode()" is also very slow...
>
> $buffer = implode("\n", $lines);
>
> doesnot end within 30 seconds, if $lines contains more than
> 3000 lines of text. Perhaps there might be a heavy mem-copy-
> operation within "implode()" function.
PHP 3.0 was never designed to do such tasks, it was designed for small to
medium scale Web applications. It's popularity grew beyond that, though,
which is why PHP 4.0 was written.
> I hope, Zend would be as fast as Perl.
It is, you can try it (http://www.php.net/version4/).
Zeev
--
-----------------------------------------------------
Zeev Suraski <zeev@zend.com> http://www.zend.com/
For a PGP public key, finger bourbon@netvision.net.il