I went through the rest of my Project Euler code.  In addition to
even?, there are some functions in clojure.contrib that are also much
slower in 1.3 Alpha 1.

clojure.contrib.math -> expt

  (Clojure 1.2)
  user=> (time (doseq [x (range 100000)] (expt x 2)))
  "Elapsed time: 119.417971 msecs"

  (Clojure 1.3)
  user=> (time (doseq [x (range 100000)] (expt x 2)))
  "Elapsed time: 10314.24357 msecs"

clojure.contrib.math -> sqrt

  (Clojure 1.2)
  user=> (time (doseq [x (range 100000)] (sqrt x)))
  "Elapsed time: 176.063438 msecs"

  (Clojure 1.3)
  user=> (time (doseq [x (range 100000)] (sqrt x)))
  "Elapsed time: 16323.254492 msecs"

For now, I've switched to using sqrt in the
clojure.contrib.generic.math-functions module (no slow-down in 1.3).
That module also has a pow function, which I was going to use as a
replacement for expt.  But pow doesn't seem to handle very large
numbers:

user=> (pow 999 999)
Infinity

So for now I'm using this as a temporary stop-gap:

(defn expt [base pow]
  (reduce *' (repeat pow base)))

Also found that sequences from clojure.contrib.lazy-seqs that used to
produce arbitrarily large numbers in 1.2 no longer do so in 1.3:

  (Clojure 1.2)
  user=> (nth (fibs) 100)
  354224848179261915075
  user=> (nth (powers-of-2) 100)
  1267650600228229401496703205376

  (Clojure 1.3)
  user=> (nth (fibs) 100)
  ArithmeticException integer overflow
clojure.lang.Numbers.throwIntOverflow (Numbers.java:1575)
  user=> (nth (powers-of-2) 100)
  0

... probably also because of 1.3's changes to numeric operations
(http://dev.clojure.org/display/doc/Enhanced+Primitive+Support).

I guess the take-away is that while playing with 1.3, be prepared to
deal with performance and/or overflow issues when using existing
numeric code (whether your own or someone else's) that doesn't yet
take into account the changes to numeric operations.

-- 
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