in reply to Re^5: Is there any XML reader like this? (XML::Simple beats LibXML hands down in the speed stakes!)
in thread Is there any XML reader like this?
Sorry, they are the same scripts as published earlier in the thread with the addition of a couple of timing points.
But here ya go. Using LibXML:
#! perl -slw use strict; use Data::Dump qw[ pp ]; use Time::HiRes qw[ time ]; use XML::LibXML; open XML, '<', $ARGV[0] or die $!; my $start = time; my $root = XML::LibXML->load_xml( IO => \*XML )->documentElement; printf "Parsing took %.6f seconds\n", time - $start; my $start2 = time; for my $station ($root->findnodes('*')) { my $x = $station->nodeName; for my $ip ( $station->findnodes('ip') ) { $x = $ip->textContent; } } printf "Iteration took %.6f seconds\n", time - $start2; printf "Total took %.6f seconds\n", time - $start; printf 'Check mem:'; <STDIN>;
And XML::Simple:
#! perl -slw use strict; use Data::Dump qw[ pp ]; use Time::HiRes qw[ time ]; use XML::Simple; open XML, '<', $ARGV[0] or die $!; my $start = time; my $stations = XMLin( \*XML, ForceArray => [ 'ip'], NoAttr => 1 ); printf "Parsing took %.6f seconds\n", time - $start; my $start2 = time; for my $station ( keys %$stations ) { my $x = $station; for my $ip ( @{ $stations->{ $station }{ip} } ) { $x = $ip; } } printf "Iteration took %.6f seconds\n", time - $start2; printf "Total took %.6f seconds\n", time - $start; printf 'Check mem:'; <STDIN>;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Is there any XML reader like this? (XML::Simple beats LibXML hands down in the speed stakes!)
by tobyink (Canon) on Jan 15, 2012 at 16:15 UTC |