Skip to content

Instantly share code, notes, and snippets.

@ytnobody
Created April 10, 2014 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytnobody/10354590 to your computer and use it in GitHub Desktop.
Save ytnobody/10354590 to your computer and use it in GitHub Desktop.
自分で作ったXML解析系モジュールのベンチとってみた
use strict;
use Benchmark qw(:all);
use XML::XPath::Diver;
use XML::Diver;
my $xml = do { local $/; <DATA> };
my $xpath_diver = sub {
my $xd = XML::XPath::Diver->new(xml => $xml);
$xd->dive('//food');
};
my $xml_diver = sub {
my $xd = XML::Diver->load_xml(string => $xml);
$xd->dive('//food');
};
cmpthese(1000, {
'XML::Diver' => $xml_diver,
'XML::XPath::Diver' => $xpath_diver,
});
__DATA__
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<breakfast_menu>
<food id="101">
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food id="102">
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
<food id="201">
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>Light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
<calories>900</calories>
</food>
<food id="202">
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>
<food id="203">
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>
</breakfast_menu>
__END__
Rate XML::XPath::Diver XML::Diver
XML::XPath::Diver 283/s -- -77%
XML::Diver 1235/s 336% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment