use strict;
use warnings;
use Data::Dumper;
use Benchmark qw(:all);
use FileHandle;
use XML::LibXML;
use XML::Atom::Feed;
use Data::Feed;
use XML::Feed;
use XML::FeedPP;
my $feed_file = q{../atom.xml};
my $fh = FileHandle->new($feed_file)
or die "cannot open $feed_file: $!";
local $/; # slurp mode
our $content = $fh->getline;
$fh->close;
cmpthese(timethese(0,
{
'XML::Atom' => \&with_xml_atom,
'Data::Feed' => \&with_data_feed,
'XML::Feed' => \&with_xml_feed,
'XML::FeedPP' => \&with_xml_feedpp,
'XML::LibXML' => \&with_xml_libxml,
}));
sub with_xml_libxml {
my @links =();
my $parser = XML::LibXML->new;
my $doc = $parser->parse_string($content);
my @nodes = $doc->findnodes(
qq{//*[name()='entry']/*[name()='link']}
);
for my $node (@nodes) {
push @links, $node->getAttribute('href');
}
# print Dumper \@links;
}
sub with_xml_feedpp {
my @links = ();
my $feed = XML::FeedPP->new($content);
foreach my $item ( $feed->get_item() ) {
push @links, $item->link;
}
# print Dumper \@links;
}
sub with_xml_feed {
my @links = ();
my $atom = XML::Feed->parse(\$content);
for my $entry ($atom->entries) {
push @links, $entry->link;
}
# print Dumper \@links;
}
sub with_data_feed {
my @links = ();
my $atom = Data::Feed->parse(\$content);
for my $entry ($atom->entries) {
push @links, $entry->link;
}
# print Dumper \@links;
}
sub with_xml_atom {
my @links = ();
my $atom = XML::Atom::Feed->new(\$content);
for my $entry ($atom->entries) {
for my $link ($entry->link) {
push @links, $link->href;
}
}
# print Dumper \@links;
}
Comments
comments powered by Disqus