Our original matrix_fib
used Python's arbitrary-size integers, which are slower than gmpy2
by a lot. To compare Binet's formula and matrix exponentiation on an even footing, we should convert the latter to use the faster GMP version, the same library that gmpy2
uses.
Now let's see what happens when we compare them!
Code
Output
81104 81104
Our original matrix_fib
used Python's arbitrary-size integers, which are slower than gmpy2
by a lot. To compare Binet's formula and matrix exponentiation on an even footing, we should convert the latter to use the faster GMP version, the same library that gmpy2
uses.
Now let's see what happens when we compare them!
Code
Output
81104 81104