RE: [PHP] Which code is faster? Better?
| From: | Crane, Christopher | Date: | Thu, 20 Jun 2002 14:04:52 +0000 |
| Subject: | RE: [PHP] Which code is faster? Better? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-103128@lists.php.net to get a copy of this message | ||
Thank you for this response. You answer was clear to me and helps me a lot.
Thanks again.
-----Original Message-----
From: Erik Price [mailto:pricee@hhbrown.com]
Sent: Thursday, June 20, 2002 9:42 AM
To: Crane, Christopher
Cc: php-general@lists.php.net
Subject: Re: [PHP] Which code is faster? Better?
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