Hi Adeshina,

I don't really understand what you're saying. I'm not very experienced with benchmarking in Go, but I think your interpretation of the results isn't correct.

With the default settings, the benchmark runs for 1 second or as long as the function takes at its first run.

So in your results Alexanders loop ran 2923 times in one second, while the memoized recursion ran only 61 times in one second.

I ran the benchmark too and the LoopOptimized version is much, much faster:

945459 ns/op

88366 ns/op

4728253 ns/op

If I raise the input to 2 million, the MemoizedRecursion finishes just once, while the loop ran 684 times.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store