F0 = 0
F1 = 1
Fn = Fn-1 + Fn-2 for n > 1
Let us challenge and compare different algorithms for the Fibonacci sequence generation!
Interestingly, the maximum Fibonacci number that can be generated on a standard modern computer with a 64-bit processor and Perl 5 installed, is
F = 1.3069892237634e+308 WOW!!!
more typically denoted as
F = 1.3069892237634 x 10308 DOUBLE WOW!!!
|As a matter of fact, 1.796 x 10308 is the largest number
that your computer can represent in 64 bits !!!
If you think that this is not impressive enough, please keep it in mind that the total number of atoms in the observable Universe as we know it, is estimated to be ca. 1080. TRIPLE WOW!!!
In my benchmark tests performed on a virtual machine box (Windows 10 x64, Intel Core i7-6700 CPU dual-core, 8 GB RAM with Perl 5) the iterative and arithmetic algorithms proved to be way faster and more effective than the recursive one. Interestingly, the iterative algorithm was 1.5 times faster than the arithmetic one as evaluated by the wall-clock time consumed by each process.