Think about Loose Coupling | |
PerlMonks |
Re: xml parsers: do I need one?by samtregar (Abbot) |
on Aug 29, 2003 at 02:29 UTC ( [id://287572]=note: print w/replies, xml ) | Need Help?? |
My first reaction was that you must be using XML::Parser incorrectly. To test my assumption I created a 3.3MB XML file with 9000 elements containing random <message> elements. Then I created a regex script (regex.pl) and an XML::Parser script (parser.pl) which both pull out all the <message> contents. I ran them head to head and made sure they both produced the same output:
So I'm seeing a simple regex beating a simple XML::Parser implementation by around 9x. Given that your regex takes three minutes, an XML::Parser script taking 35 minutes is within a similar multiple. When you consider that XML::Parser is making multiple Perl sub calls on each element it encounters, I guess it makes sense. But, still, ouch!. Of course, if it were my job on the line I'd still use an XML parser. I've been bitten by changing specifications and funky data too many times to take the easy way out in the parser. In fact, these days I parse my XML twice - first with Xerces/C++ for schema validation and second with XML::Simple for actual usage. Better safe than sorry! -sam
For the record, here's my test setup. First, the data generator:
The regex parser:
And the XML::Parser script:
In Section
Seekers of Perl Wisdom
|
|