November 2017
Intermediate to advanced
670 pages
17h 35m
English
We have heard that recursion in Go can be slow. So, let's write some benchmark tests to check it out. First, let's test the performance of the basic imperative function SumLoop:
func benchmarkSumLoop(s []int, b *testing.B) { for n := 0; n < b.N; n++ { SumLoop(s) }}func BenchmarkSumLoop40(b *testing.B) { benchmarkSumLoop([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40}, b) }
Results: It took 46.1 ns/op.