Re: Too slow execution time.

From: Date: Sat, 02 Oct 1999 10:17:03 +0000
Subject: Re: Too slow execution time.
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-11428@lists.php.net to get a copy of this message
On Sat, 2 Oct 1999, Zeev Suraski wrote: > 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"); > > } please try: $cnt = count($lines); for ($i = 0; $i < $cnt; $i++) .... that should speedup that script a *LOT*! tc > > > > 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 > > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > Thies C. Arntzen "One Big-Mac, Small Fries and a Coke!" Digital Collections Phone +49 40 235350 Fax +49 40 23535180 Hammerbrookstr. 93 20097 Hamburg / Germany

« previous php.dev (#11428) next »