#! perl -slw
use strict;
$|++;
our $S //= '999';
our $I //= 10;
open O, '>', 'junk.xml';
print O '<servers>';
for my $s ( '0001' .. $S ) {
printf "\r%s", $s;
print O "<station$s>";
print O '<ip>', join('.', unpack 'C4', pack 'N', int( rand 2**32 )
+ ), '</ip>' for 1 .. $I;
print O "</station$s>";
};
print O '</servers>';
close O;
Like this: C:\test>xmlgen -S=9999
9999
C:\test>dir junk.xml
15/01/2012 12:40 2,424,205 junk.xml
Now run XML::Simple & XML::LibXML scripts that parse that file and iterate the contents and time them: C:\test>xmllib junk.xml
Parsing took 0.290895 seconds
Iteration took 171.657306 seconds
Total took 171.959000 seconds
Check mem:63.6MB
C:\test>xmlsimple junk.xml
Parsing took 38.202000 seconds
Iteration took 0.059186 seconds
Total took 38.262577 seconds
Check mem:142MB
All the time you gained during parsing, you throw away four-fold when accessing the data through the nightmare interface of OO baloney.
And if you double the file size: C:\test>xmlgen -S=19999
19999
C:\test>dir junk.xml
15/01/2012 12:58 4,868,440 junk.xml
And now LibXML takes 8 times as long: C:\test>xmllib junk.xml
Parsing took 0.560000 seconds
Iteration took 676.238758 seconds
Total took 676.802000 seconds
Check mem:107MB
C:\test>xmlsimple junk.xml
Parsing took 75.078000 seconds
Iteration took 0.124583 seconds
Total took 75.209615 seconds
Check mem:254MB
Increase the file size 10-fold and LIbXML will take 100 time longer.
Now look carefully at the split times. XML::Simple's parsing time is slow, but linear with the file size. It's traversal time is extremely fast and also linear.
Conversely, LibXML's parsing time is very fast and linear; but it's traversal time is horribly slow and quadratic with the file size.
It is easy to see which one wins in the speed stakes.
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".
|