Re: Fibonacci function performance compare between clojure and scala

2008-10-19 Thread Meikel Brandmeyer
Hello, Am 19.10.2008 um 17:56 schrieb Lauri Oherd: There is also a faster way to calculate fibonacci numbers in Clojure (code taken from from http://en.wikibooks.org/wiki/Clojure_Programming#Lazy_Fibonacci): (defn fib-seq [] ((fn rfib [a b] (lazy-cons a (rfib b (+ a b 0 1)) user=

Re: Fibonacci function performance compare between clojure and scala

2008-10-19 Thread [EMAIL PROTECTED]
This lazy cached calculate is wonderful ,but i think the benefit from it mostly due to cache . On Oct 19, 11:56 pm, "Lauri Oherd" <[EMAIL PROTECTED]> wrote: > There is also a faster way to calculate fibonacci numbers in Clojure > (code taken from > fromhttp://en.wikibooks.org/wiki/Cloju

Re: Fibonacci function performance compare between clojure and scala

2008-10-19 Thread Lauri Oherd
There is also a faster way to calculate fibonacci numbers in Clojure (code taken from from http://en.wikibooks.org/wiki/Clojure_Programming#Lazy_Fibonacci): (defn fib-seq [] ((fn rfib [a b] (lazy-cons a (rfib b (+ a b 0 1)) user=> (time (take 38 (fib-seq))) "Elapsed time: 0.0329

Re: Fibonacci function performance compare between clojure and scala

2008-10-19 Thread [EMAIL PROTECTED]
Scala is sure to use java primitive int type underline, i.e value type and boxed to java Integer when necessarily But why not Clojure auto make this ? gerry On Oct 19, 11:31 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Here is coersion version for Clojure > > (defn fib [n] >   (l

Re: Fibonacci function performance compare between clojure and scala

2008-10-19 Thread [EMAIL PROTECTED]
Here is coersion version for Clojure (defn fib [n] (let [n (int n)] (if (or (zero? n) (= n 1)) 1 (+ (fib (dec n) ) (fib (- n 2)) (time (fib 36)) "Elapsed time 8848.865149" not much better and how to type hint for a int type? --~--~-~--~~

Re: Fibonacci function performance compare between clojure and scala

2008-10-19 Thread Parth Malwankar
On Oct 19, 7:49 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Clojure's > > (defn fib [n] >(if (or (zero? n) (= n 1)) >1 > (+ (fib (dec n) ) (fib (- n 2) > > (time (fib 36)) > > "Elapsed Time: 10475.325226 msecs" > 24157817 > > Scala's > > def fib(n:Int):Int=if (

Re: Fibonacci function performance compare between clojure and scala

2008-10-19 Thread Rastislav Kassak
Just use type hint in Clojure version and you'll see quite a difference in performance. Your scala version is completely optimized / crippled to integers (maybe even unboxed), so there is no dynamic runtime overhead. IMHO, this kind of microbenchmarks are just good for finding general weak point