Superlman has asked for the wisdom of the Perl Monks concerning the following question:
In which &ReallyConmplexFunction takes a few seconds to evaluate, and $foo changes with each iteration, but $bar may or may not. Since I don't know, I can't take &ReallyComplexFunction out and do something likewhile($foo < &ReallyComplexFunction($bar)) { doStuff(); }
...since $bar may change.$foobar = &ReallyComplexFunction($bar) while($foo < $foobar) { doStuff(); }
I was thinking it would be rather nifty if the results of a function were cached, so that if the function was called multiple times with the same input, the output would be nearly instantaneous after the first time. (Yes, I realize how undesirable this would be for the vast majority of functions- imagine if the results of time were cached!)
What would be an efficient way to do something like this? Does Perl have some kind of optimizer that renders my question pointless?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Efficiency and Functions in loops
by suaveant (Parson) on Oct 11, 2001 at 22:09 UTC | |
|
Re: Efficiency and Functions in loops
by perrin (Chancellor) on Oct 11, 2001 at 22:18 UTC | |
|
Re: Efficiency and Functions in loops
by blakem (Monsignor) on Oct 11, 2001 at 22:19 UTC | |
|
Re: Efficiency and Functions in loops
by thinker (Parson) on Oct 11, 2001 at 22:20 UTC | |
|
Re: Efficiency and Functions in loops
by dragonchild (Archbishop) on Oct 11, 2001 at 22:10 UTC | |
by suaveant (Parson) on Oct 11, 2001 at 22:17 UTC | |
|
Re: Efficiency and Functions in loops
by George_Sherston (Vicar) on Oct 11, 2001 at 22:33 UTC | |
by blakem (Monsignor) on Oct 11, 2001 at 22:36 UTC |