I tried to calc the first 40 numbers, it tooks in my PC about 16 minutes. I weren't worried about writting a fast algoritm, just curious about the performance of a recursive call algorithm.
A friend of me, advertised me that the similar Java version code, ran fast, so I tried:
// Java fibonnaci class
class fibo {
public static long calc(long x) { if( x < 2 ) return 1; return calc(x-1) + calc(x-2); }
I'm not looking for a cache model like memoize. I only want to focus on the time taken by each program (Java, Perl) with a similar original code. I think Java does some kind of memoize at low level, doesn't it?
Java will look for heavily used sections of code, aggressively optimize them, and rewrite in machine code. That is the reason for the performance difference.
Memoize (Score:1)
Re: (Score:1)
Re: (Score:1)
No. It just has fundamentally different execution model.
Re: (Score:1)
Re: (Score:1)
Java will look for heavily used sections of code, aggressively optimize them, and rewrite in machine code. That is the reason for the performance difference.
O(2^n) (Score:1)
It's also the classic example (it's in SICP) of how a bad algorithm choice can get really slow really fast.