Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

boo_radley (2349)

boo_radley
  (email not shown publicly)

Journal of boo_radley (2349)

Monday February 04, 2002
11:47 AM

When XML::Twig Attacks !

[ #2644 ]
While plowing my way through Damian Conway's Object Oriented Perl, I read something to the effect that, yes, you can type variables. so rather than

my $foo = Bar::Baz->new();

a script can define
my Bar::Baz $foo = Bar::Baz->new();
and $foo's methods will get checked at compile time, rather than run time, shaving precious time off script execution. Intrigued, I decided to benchmark. I couldn't think of anything that I was using that didn't make :

use Benchmark;
use XML::Twig;
$count=50000;
Benchmark::cmpthese($count, {
'typed' => sub {
my XML::Twig $twig=XML::Twig->new();
#$twig->parsefile( 'c:\test.xml');
},
'untyped' => sub {
my $twig=XML::Twig->new();
#$twig->parsefile( 'c:\test.xml');
},
});


This brought my memory usage to a little over 800 meg after the benchmark was done. The lesson being "When a module says 'be sure to call dispose after you're done with an object', you do it!". Although, after I corrected the benchmark subs, I still wound up short 20 MB or so after all was said and done. Very mysterious.

Oh, the results?

Benchmark: timing 50000 iterations of typed, untyped...
typed: 19 wallclock secs (17.56 usr + 0.00 sys = 17.56 CPU) @ 2847.06/s (n=50000)
untyped: 20 wallclock secs (19.12 usr + 0.00 sys = 19.12 CPU) @ 2614.38/s (n=50000)
Rate untyped typed
untyped 2614/s -- -8%
typed 2847/s 9% --


I think I need to work up a larger test case.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • 'Typing' your variables will not get you a speed increase unless the variable being typed is a pseudo-hash object and you're accessing the hash keys directly.

    IOW, don't bother.

    -dave
  • The lesson being "When a module says 'be sure to call dispose after you're done with an object', you do it!". Although, after I corrected the benchmark subs, I still wound up short 20 MB or so after all was said and done.

    Actually if you are using XML::Twig 3.00 or above and perl 5.6.1 or above you should read the part that advises you to install WeakRef [cpan.org] as it would remove the need to dispose ;--)