Running a time command on my macbook pro (core 2 duo, 2.4 ghz) i get the following results :
real 0m36.345s user 0m35.354s sys 0m0.371s
Not bad, faster than python, comparable to java, but nowhere near the C equivalent. Through reading the book i came across the concept of Pattern matching, so i thought i would re-write my naive fib to take advantage of it :
object pat {
def fibMatch (n: Int): Int = n match { case 0 => n case 1 => n case _ => (fibMatch (n - 1) + fibMatch (n - 2)) }
So my question is, how can these differences be explained? Its the same naive algorithm as far as i can tell, no previous results are being held in arrays or matrices or anything. Obviously some sort of optimisation is done by the compiler in the pattern matching case, what is it? For the record when i use JIT compiling using the psyco module with python i get similar results :
real 0m2.180s user 0m2.157s sys 0m0.021s
Anyway, im back to read more of the book and see what else is in store!
Right i've figured it out, i used BigInt in the first example, and Int in the second, guess thats the performance difference for using BigInts. I feel pretty dumb now ;)