Re: Which code is faster? Better?

From: Date: Thu, 20 Jun 2002 13:41:40 +0000
Subject: Re: Which code is faster? Better?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-103121@lists.php.net to get a copy of this message
On Thursday, June 20, 2002, at 09:07 AM, Crane, Christopher wrote:
I have written and I am wondering which is faster and which is better. I think if it's a page with a lot of data on it, the first example may be better because I am not reading in the entire file...but I am not sure if it's the best way to do it.
Exactly. If it's a lot of data, just do line-by-line parse and process (if possible). However if it's not a lot of data, you could slurp the file and deal with it then. Think of the difference between SAX and DOM in respect to XML processing. SAX is lightweight because it runs through the file and triggers events when it comes across certain tags, whereas DOM builds an internal node tree in memory and lets you manipulate it directly. For complex work, DOM is easier to work with because you can refer to nodes directly rather than setting up a complex network of event handlers as you must do in SAX, but you need the memory to handle the overhead of having all of that information in memory. Erik ---- Erik Price Web Developer Temp Media Lab, H.H. Brown pricee@hhbrown.com

« previous php.general (#103121) next »