On Tue, May 10, 2011 at 2:21 PM, Carl Cotner <carl.cot...@gmail.com> wrote:

> Hi,
>
> Is it possible to make Clojure run the following toy program faster
> (without changing the algorithm)?
>
> (defn primeQ [n] (primes 2 (/ n 2) n))
>
> (defn divQ [d n] (= (mod n d) 0))
>
> (defn primes [d2 t2 n2]
>  (loop [d (int d2) t (int t2) n (int n2)]
>    (if (divQ d n) false
>        (if (> d t) true
>            (recur (inc d) t n)))))
>
> Running this on my machine:
>
> user> (time (primeQ 71378569))
> "Elapsed time: 11047.721488 msecs"
>
> is roughly 13 times slower than running the comparable Java program.
> It seems like one should be able to do much better for such a
> straightforward program. Is there anything I can do to make this
> program faster?
>
> Thanks,
> Carl


It doesn't answer your question but maybe this will help you get some ideas
on how to optimize your code:
http://dosync.posterous.com/lispers-know-the-value-of-everything-and-the

For this kind of thing to be competitive w/ Java it's best that you work
with a 1.3 alpha or the master branch.

David

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to