XML::Simple におけるパーサーの実行速度比較

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Benchmark: running XML::LibXML::SAX, XML::Parser, XML::SAX::Expat, XML::SAX::ExpatXS, XML::SAX::PP for at least 3 CPU seconds...
XML::LibXML::SAX:  3 wallclock secs ( 3.03 usr +  0.00 sys =  3.03 CPU) @ 20.79/s (n=63)
XML::Parser:  3 wallclock secs ( 3.11 usr +  0.01 sys =  3.12 CPU) @ 57.30/s (n=179)
XML::SAX::Expat:  3 wallclock secs ( 3.27 usr +  0.00 sys =  3.27 CPU) @ 18.38/s (n=60)
XML::SAX::ExpatXS:  3 wallclock secs ( 3.30 usr +  0.00 sys =  3.30 CPU) @ 67.33/s (n=222)
XML::SAX::PP:  3 wallclock secs ( 3.25 usr +  0.00 sys =  3.25 CPU) @  4.00/s (n=13)
Rate XML::SAX::PP XML::SAX::Expat XML::LibXML::SAX XML::Parser XML::SAX::ExpatXS
XML::SAX::PP      4.00/s           --            -78%             -81%        -93%              -94%
XML::SAX::Expat   18.4/s         360%              --             -12%        -68%              -73%
XML::LibXML::SAX  20.8/s         420%             13%               --        -64%              -69%
XML::Parser       57.3/s        1333%            212%             176%          --              -15%
XML::SAX::ExpatXS 67.3/s        1584%            266%             224%         18%                --
 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use strict;
use warnings;
use Benchmark qw(:all);
use Perl6::Say;
use FileHandle;
use XML::Simple;
use Data::Dumper;
my $rss_file = "../satomi.xml";
my $fh = FileHandle->new($rss_file)
or die "cannot open $rss_file: $!";
local $/; # slurp mode
our $content = $fh->getline;
$fh->close;
sub parse {
my $xml = XML::Simple->new->XMLin($content);
#    say Dumper $xml;
}
cmpthese(timethese(0,
{
'XML::Parser'       => \&with_xml_parser,
'XML::LibXML::SAX'  => \&with_xml_libxml_sax,
'XML::SAX::ExpatXS' => \&with_xml_sax_expatxs,
'XML::SAX::Expat'   => \&with_xml_sax_expat,
'XML::SAX::PP'      => \&with_xml_sax_pp,
}));
sub with_xml_parser {
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
parse();
}
sub with_xml_sax_pp {
$XML::Simple::PREFERRED_PARSER = 'XML::SAX::PurePerl';
parse();
}
sub with_xml_libxml_sax {
$XML::Simple::PREFERRED_PARSER = 'XML::LibXML::SAX';
parse();
}
sub with_xml_sax_expatxs {
$XML::Simple::PREFERRED_PARSER = 'XML::SAX::ExpatXS';
parse();
}
sub with_xml_sax_expat {
$XML::Simple::PREFERRED_PARSER = 'XML::SAX::Expat';
parse();
}

Comments

comments powered by Disqus