PHP5 XML at 10Meg

Tweet

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.

Get your free chapter of Level Up Your Web Apps with Go

Get a free chapter of Level Up Your Web Apps with Go, plus updates and exclusive offers from SitePoint.

  • 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.