In this section, I will show you a basic benchmarking example that will measure the performance of three algorithms that generate numbers belonging to the Fibonacci sequence. The good news is that such algorithms require lots of mathematical calculations, which makes them perfect candidates for benchmarking.
For the purposes of this section, I will create a new main package, which will be saved as benchmarkMe.go and presented in three parts.
The first part of benchmarkMe.go is as follows:
package main import ( "fmt" ) func fibo1(n int) int { if n == 0 { return 0 } else if n == 1 { return 1 } else { return fibo1(n-1) + fibo1(n-2) } }
The preceding code contains the implementation of the fibo1() function, which uses recursion in order to calculate numbers of the Fibonacci sequence...