Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

use Memoize;

by Anonymous Monk
on Jul 16, 2018 at 19:18 UTC ( [id://1218607]=perlmeditation: print w/replies, xml ) Need Help??

I was porting a script to a module and noticed it kept getting slower. The script could initialize its expensive data structure once at the top and be done with it, but in order to encapsulate, the module was calling the function several times. I remembered the core module Memoize and added one line to the top of the program and now it runs fast again, 4x faster than without Memoize!

use Memoize; memoize('some_sub');

Only 1.5 seconds to start a program that was taking 6 seconds!

Replies are listed 'Best First'.
Re: use Memoize;
by Athanasius (Archbishop) on Jul 17, 2018 at 02:45 UTC
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://1218607]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-23 07:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found