PHP5 XML at 10Meg

Christian has some interesting thoughts, results and code up here, parsing a 10Mb XML document with PHP5’s XML apis. Highlights the trade off between performance and memory use when using DOM vs. Sax / XMLReader.

Personally a little surprised that XMLReader proved faster than SAX. “Pull style” XML parsers are usually implemented by “re-routing” a SAX parser and from a quick glance at the libxml2 source, it seems to do the same. I guess executing alot of callback functions at a C level is faster than executing them up at the PHP level.

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • chregu

    Harry, you’re right. PHP Functions calls are really really slows compared to C function calls. And in SAX, there are a lot of them (on the PHP level), while with XMLReader you have almost none, just the while() looping.