Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^6: Is there any XML reader like this? (XML::Simple beats LibXML hands down in the speed stakes!)

by BrowserUk (Pope)
on Jan 15, 2012 at 13:56 UTC ( #947993=note: print w/replies, xml ) Need Help??


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>;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

  • Comment on Re^6: Is there any XML reader like this? (XML::Simple beats LibXML hands down in the speed stakes!)
  • Select or Download Code

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 (Abbot) on Jan 15, 2012 at 16:15 UTC

    The LibXML example uses findnodes which is an XPath query. XPath, while extremely powerful, is not necessarily the most speedy solution, and it's not an especially fair comparison to the XML::Simple example. Replacing findnodes calls with getChildrenByTagName (the rest of the code can remain unchanged) speeds up the iteration tenfold. I get:

    [tai@miranda (pts/0) libxml]$ perl orig.pl junk.xml
    Parsing took 0.077047 seconds
    Iteration took 6.021286 seconds
    Total took 6.098525 seconds
    [tai@miranda (pts/0) libxml]$ perl new.pl junk.xml
    Parsing took 0.105245 seconds
    Iteration took 0.631286 seconds
    Total took 0.736719 seconds
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://947993]
help
Chatterbox?
[james28909]: Good morning!
[james28909]: I have a problem I am trying to solve. I am packaging scripts using pdk and would like the verify the executable name each time it is executed
[Corion]: Hi James!
[james28909]: I looked through the docs, and see that PerlApp::exe() is suppose to return this information but whenever i try to use this, i get the error "Undefined subroutine &PerlApp::exe called"
[james28909]: i just want to verify the integrity of the executables name each time it is run.
[Corion]: Weird. this documentation says what you say.
[Corion]: I assume you are experiencing this with your packaged program. Maybe also include PerlApp.pm in the packaging list?
[james28909]: has anyone else run into this problem? i have tried searching but have not returned many results
[james28909]: ah, good idea.
[Corion]: What does print $PerlApp::VERSION output?

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2017-07-28 13:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (429 votes). Check out past polls.