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?
In reply to Efficiency and Functions in loops by Superlman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |