Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Welcome to the Monastery
 
PerlMonks  

Re: May Thy Closures Be Blessed

by Abigail-II (Bishop)
on Apr 26, 2004 at 17:51 UTC ( [id://348337]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re^3: May Thy Closures Be Blessed
in thread May Thy Closures Be Blessed

Very nice. Big savings because of caching the calculation of stringified value (I get an 18% difference, not a 3%). Unfortunally, this technique can't be used if you are subclassing a class that doesn't coorperate - then you will to call refaddr in each method. That's slower (traditional method being 69% faster), but faster than what I showed before. I would have expected to be able to gain a little more by writing the methods like:
sub name { my $key = ${+shift}; $name {$key} = shift if @_; $name {$key}; }
but that doesn't give me any gain (or loss).

Abigail

Replies are listed 'Best First'.
Re^2: May Thy Closures Be Blessed
by adrianh (Chancellor) on Apr 26, 2004 at 18:37 UTC
    I get an 18% difference, not a 3%

    Hmm. I do seem to have been lucky with my initial runs. I'm seeing between 3-10% on my box, but nothing near 18%. How odd.

    Unfortunally, this technique can't be used if you are subclassing a class that doesn't coorperate

    True. Although for hash based objects you could just use one slot for the key and still get safety for all your other state hashes.

    I would have expected to be able to gain a little more by writing the methods like ...

    Good point. Can any internals expert explain why +shift is so slow?

      Although for hash based objects you could just use one slot for the key and still get safety for all your other state hashes.
      True, but then you make yourself dependent on the implementation of the superclass. It opens the door to collisions, and you get a problem when the superclass changes its implementation (say, it starts to use restricted hashes).

      Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://348337]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.