in reply to Re^3: fibonacci numbers using subroutine?
in thread fibonacci numbers using subroutine?
You don't need to Memoize fib_memo(), the memoisation is already built in! That's what the state variable %memo is for.
Once you remove that, the real performace shows up (This is for (1..100)):
c:\test>junk21 Benchmark: timing 10000 iterations of Memo, Normal... Memo: 1 wallclock secs ( 0.64 usr + 0.00 sys = 0.64 CPU) @ 15 +649.45/s (n=10000) Normal: 15 wallclock secs (14.98 usr + 0.01 sys = 14.99 CPU) @ 66 +7.07/s (n=10000)
The difference is all the clearer with my preferred cmpthese() (why do you use timethese()?):
c:\test>junk21 Rate Normal Memo Normal 669/s -- -96% Memo 15573/s 2229% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: fibonacci numbers using subroutine?
by Marshall (Canon) on Aug 20, 2010 at 13:06 UTC | |
by JavaFan (Canon) on Aug 20, 2010 at 13:13 UTC | |
by BrowserUk (Patriarch) on Aug 20, 2010 at 13:23 UTC |