Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Hair Splitting?

by harleypig (Scribe)
on Dec 13, 2001 at 01:17 UTC ( #131411=perlquestion: print w/ replies, xml ) Need Help??
harleypig has asked for the wisdom of the Perl Monks concerning the following question:

I ran across the following line of code in Class:Struct and was curious about it. I did some benchmarks and, depending on what and how it was used, it was anywhere from 10-15% faster for large iterations than what I would have used.


my $isa = do {
  no strict 'refs';
  \@{$class . '::ISA'};
};

I would have used the following:


my $isa;
{ no strict "refs";
  $isa = \@{$class . '::ISA'};
}

Now, I understand *what* is happening with Damien's code, but not *why* it's so much faster. I'm thinking it has something to do with the separation of the declaration and definition of the $isa variable, but I don't see why.

Any ideas?

Harley J Pig

Comment on Hair Splitting?
(tye)Re: Hair Splitting?
by tye (Cardinal) on Dec 13, 2001 at 02:07 UTC

    So how long does you script take to run and how many times does you script execute such code per run? For example, if your script takes 0.01 seconds to run, and you execute this code 100 times per run, then, based on my benchmarks, the 15% speed-up in this code will make your script run about 0.000063 seconds faster, or less that 0.6% faster.

    I suspect that your script takes longer than that to run and that it doesn't execute that code that many times so your "savings" are even more miniscule.

    But to answer you question, "I don't care." (:

    When benchmarking, I mostly discount difference under 20% as a 5% or 10% difference can often be due to which test gets run first, or other unimportant details and so 20% is a pretty minor difference.

    But most benchmarks I see (even most of the ones I've done) are timing microscopic operations and so even a 10-fold speed increase is likely to be nearly completely dwarfed by the rest of the work being done. Now, when you benchmark a microscopic operation that your script doesn't even do a few thousand or million times, then you are really going to a lot of work to fairly accurately measure how insignificant the change is, and then focusing on the wrong number.

    And when you do these benchmarks before you have even identified that you have a performance problem and that the operation is in fact part of a bottleneck, then you are pre-optimizing. And premature nano-optimization is very common (at least in Perl circles) and can be kind of fun, but you should mostly ignore it beyond the "fun" aspect.

    So I might find it fun if someone figures out the cause of this speed difference. But I don't really care. :)

            - tye (but my friends call me "Tye")

      I don't really care about the speed difference. I'm not trying to optimize anything. I just want to know what's happening with the 'Conway' method and *why* there is a speed increase ... no matter how insignificant.

      The 'Conway' method is certainly more perlish though. :)

      Harley J Pig

Re: Hair Splitting?
by TheDamian (Priest) on Dec 13, 2001 at 16:43 UTC

    You know what: I have no idea why my version is faster. I didn't specifically write it that way to get better performance: to me it just seemed the obvious way to do it.

    But that's precisely what I love about Perl: as a general rule, the more Perlishly you code, the faster the code runs!

    Sorry not to be able to offer you enlightenment, but when it comes to Perl internals, I am (quite happy to remain) an utter novice.

    ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://131411]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2014-09-23 22:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls