News for hackers. Stuff that matters.
Re:Node.js cures cancer by ricardobeat on Monday October 03, 2011 @05:34AM (#3065616)
I wasn't. I was just curious about the huge difference in performance. These numbers are from printing to console, no servers.

    def fibonacci(n):
        t = [0, 1]
        for i in xrange(n):
            t.append(t[-1] + t[-2])
        return t[-2]
    
    print fibonacci(800)
Re:Node.js cures cancer by th_yc on Tuesday October 04, 2011 @06:53PM (#3073316)
Technically the above is a dynamic programming algorithm, in that you are avoiding the recomputation of fib(1..n-1) in each step. That is equivalent to recursion+memoization, which would perform roughly similar to the above. So it is not that "recursion" is so dramatically slower than "iteration" in general, it's just that for these kinds of computations, recursion should be memoized.