Open schafer14 opened 4 years ago
I have a gist with a more complete listing if that is helpful.
https://gist.github.com/schafer14/266fb061a73b5e31df72a1efe7ef471a
Let me know if I can provide more helpful information.
I can confirm the same problem after running my benchmarks. The correct implementation is in file memoize.go_ORIG. memorize.go memoizes only the result but intermediate numbers and it's misleading.
I may have found an issue with the listing for the Fibonacci sequence using memoization. I think that there is a correct implementation in the memoize.go_ORIG but the memorize.go is not working as expected.
It looks to me like the current implementation is only caching the result of the outer function, not the intermediate steps. The benchmarks are misleading because they average all of the runs to generate the ops/sec metric. I think what is happening is the first call is taking a long time but each subsequent call is extremely quick and hence the average is very quick.
I wrote an example that I think demonstrates this:
where FibMem is the listing in the book and FibMem2 is the old listing. The results are
There is also a chance I am just getting mixed up. Could you help me work through this?
Thanks