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();
}
|