--

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:

BenchmarkLoop100000-12
1090
945459 ns/op

BenchmarkLoopOptimized100000-12
13860
88366 ns/op

BenchmarkMemoizedRecursion100000-12
33
4728253 ns/op

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

--

--

Responses (1)