3 ms·
Is there a reason that these examples are using some sort of deeply nested call stack? Is it just to enforce 'slowness' in the function calls? def fibonacci(
by vessenes 15y ago
Is there a reason that these examples are using some sort of deeply nested call stack? Is it just to enforce 'slowness' in the function calls?
def fibonacci(n):
a,b = 0,1
for i in range(0,n):
a,b, = b,a+b
return b
(cadged from zacharyfox.com) performs far, far better than the nested function calls. I imagine it would in javascript as well. In python at least, all that function calling infrastructure is relatively expensive.
- xtacy 15y agoIt's just a canonical form; it's far easier (IMHO) for a beginner to understand a recursively written Fibonacci number computer than your function.
- vessenes 15y agoI hear that. In this case, though the entire blog article was complaints about slowness, or blocking behavior as seen through slowness.
- jcampbell1 15y ago> Is it just to enforce 'slowness' in the function calls? Yes. He was just illustrating a point about blocking on the CPU.