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 (n==0||n==1)1 else fib(n-1)+fib(n-2)
> def time(cal: =>Int)={
>  val beginTime=System.currentTimeMillis
>  cal
>  val endTime=System.currentTimeMillis
>  println(endTime-beginTime)}
>
> fib(36)
> res70:Int=24157817
> time(fib(36))
> 263
>

I am not a scala expert but I suspect scala Int maps directly to
java ints.

In clojure, the number are boxed and checked by default IIRC.
This would roughly correspond to BigInt in scala.

For clojure, you could coerce ints to native java types using
(int ..).
Also, unchecked-dec could be used.
Doing this should make the code as fast as java or scala.
There was some discussion along these lines here:
http://groups.google.com/group/clojure/browse_thread/thread/4274ce8bd44664ef#

That said, for most practical uses the default behavior
should be fast enough. Its not considered idiomatic to
use coersion and unchecked operation unless absolutely
necessary.

Parth


> Both not tail recursive,both running on Repl (scala's interpreter),but
> the difference between two is huge
> 10475~263
> My box : Intel core2 cpu 1.86G,2G mem
> Clojure and scala both latest build from svn
>
> any ideas?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to