Memoize
use Memoize; sub fib_memoized { my ($n) = @_; if ($n > 1) { return fib_memoized($n - 1) + fib_memoized($n - 2); } return $n; } memoize('fib_memoized');
Memoized - first run 0.000333 Memoized - second run 0.000011