Rebecca Peltz
Jan 27, 2025

--

I really enjoyed reading your article. I've been using around with Fibonacci calculations comparing performance in python to node.js. I get a timer count for each of the method calls. I was just just testing iteration, recursion and yield (you didn't mention yield). I added your methods and here are the results in Python (node.js is slower on everything). Thanks for sharing! Doesn't seem like a great interview question, but if you're playing around with data it's nice to have all of these methods. These result were gathered from running the methods with nth Fib of 10:

55, 0.002145767, iter_fib

55, 0.003099442, yield_fib

55, 0.013828278, recur_fib

55, 0.002145767, tco_fib

55, 0.004053116, memo_fib

55, 0.009059906, matrix_fib

55, 0.003099442, dp_fib

55, 0.003814697, double_fib

55, 0.004291534, binet_fib

Interesting that iteration and TCO have the same performance result for me and they are the fastest. Matrix is the slowest. Cheers!

--

--

Rebecca Peltz
Rebecca Peltz

Written by Rebecca Peltz

Software/Web Engineer and Instructor

Responses (1)