Benchmarking many Fibonacci functions and algorithms with running unit test ...
Fibonacci's numbers are special kinds of numbers that form a special sequence. This sequence is one of the famous formulas in mathematics. You can find Fibonacci numbers in plant and animal structures. These numbers are also called nature's universal rule, and nature's secret code.
Fibonacci's numbers are a sequence of whole numbers arranged as:-
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
there are so many code in the net to get Fibonacci number, but I think I can do better
- collect the methods used to get Fibonacci in go ✅
- run unit test to check and correct (some function start form 1 not 0) ✅
- check function limitation ✅
- benchmark ✅
- try to make/modify/enhance for best results ✅
As in the table above we made our best results with the last function (Func14). Some function excluded from the table because it will be very slow in big number because they use iteration method. The fast doubling is the fastest reliable method ... The Binet formula will be faster, but it will not be accurate since we have to use floating point. There are many tricks to increase the speed. The main one is using Goroutine to run two equation concurrently. the other is to use table for the first 1025 fib numbers. the table will take about 200KB. will be used to get the fib number directly for the first 1025. the other use of the table is to remove the first 10 iteration of the fast doubling(2^10 =1024).
++++++++++++++++++++++++++++++++++++++++++++++++++++++++