Categories
Archives
- March 2010 (1)
- January 2009 (1)
- November 2008 (4)
- October 2008 (4)
- September 2008 (1)
- August 2008 (4)
- July 2008 (4)
- June 2008 (1)
- May 2008 (1)
- April 2008 (2)
- February 2008 (2)
- January 2008 (4)
- December 2007 (1)
- September 2007 (1)
- July 2007 (4)
- June 2007 (7)
- May 2007 (5)
- April 2007 (2)
- March 2007 (1)
- January 2007 (1)
- August 2006 (5)
Tags
- accident aging amanda animals art backup bald benchmark birds bizarre blood cake caligola car clothes debian dell dof dog bite dogs filesystems fotozondagavond garden hair holiday house injury insects italy leak linux luxury metal multimedia music nature nvidia perl pets presidents privacy programming pusa running sofia sound source spelling spiders sports spring surgery suspend sysadmin test thailand unix vampires vijntje water xml youth sentiment
Links
XML::Parser or XML::LibXML?
August 28th, 2008
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
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,
{
'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.
