That’s an easy question to answer: XML::LibXML!
I have over 10,000 lines of XML input. Parsing it into a tree with XML::Parser takes about 0.77 seconds, while XML::LibXML is over ten times faster, clocking in at 0.07 seconds.
#!/usr/bin/perl
use strict;
use Benchmark qw( cmpthese timethese :hireswallclock );
use XML::Parser;
use XML::LibXML;
sub xml_parser {
my $p1 = new XML::Parser(Style => 'Tree');
my $tree = $p1->parsefile('database.xml');
}
sub xml_libxml {
my $p1 = new XML::LibXML;
my $tree = $p1->parse_file('database.xml');
}
my $results = timethese(15,
{<tt>
'XML::LibXML' => \&xml_libxml,
'XML::Parser' => \&xml_parser,
},
'noc',
);
print "\n";
cmpthese($results);
The results are pretty damning:
XML::LibXML: 1.06607 wallclock secs ( 1.01 usr + 0.03 sys = 1.04 CPU) @ 14.42/s (n=15)
XML::Parser: 11.5305 wallclock secs ( 9.20 usr + 1.14 sys = 10.34 CPU) @ 1.45/s (n=15)
Rate XML::Parser XML::LibXML
XML::Parser 1.31/s -- -91%
XML::LibXML 14.4/s 1005% --
Now it’s off to write a schema for our wondrous XML dialect.
