On Aug 8, 2:16 pm, John Harrop <jharrop...@gmail.com> wrote: > On Sat, Aug 8, 2009 at 5:23 AM, Mark Engelberg > <mark.engelb...@gmail.com>wrote: > > > > > On Fri, Aug 7, 2009 at 5:14 PM, John Harrop<jharrop...@gmail.com> wrote: > > > (if (and (not (= 0 i)) (< (+ zr2 zi2 limit-square))) > > > I believe that (zero? i) is faster than (= 0 i). > > On primitive ints? Have you tested it?
I have, now, at your suggestion. Here are the results on my iMac, 2.16 GHz Intel Core 2 Duo, Mac OS X 10.5.8, Java version: % java -version java version "1.6.0_13" Java(TM) SE Runtime Environment (build 1.6.0_13-b03-211) Java HotSpot(TM) 64-Bit Server VM (build 11.3-b02-83, mixed mode) All are for the mandelbrot.clj-3.clj program here: http://github.com/jafingerhut/clojure-benchmarks/blob/3e45bd8f6c3eba47f982a0f6083493a9f076d0e9/mandelbrot/mandelbrot.clj-3.clj (By the way, these links should not be to blank pages, as you experienced earlier. I can follow them when reading in the Clojure group web page, or in my email client. Perhaps the software you are using to read these messages is truncating the URLs, and thus they are not going to the intended place? Sorry they are so long, which tends to cause these kinds of issues.) I did two runs for each version, with the only difference between them being replacing the (zero? i) expression in function 'dot' with a different expression, as indicated below. (zero? i) is a clear winner in reducing run time. If it makes a difference, I'm also using latest github clojure and clojure-contrib as of about August 6, 2009. Here is what the REPL says about the definition of zero? % clj Clojure 1.1.0-alpha-SNAPSHOT user=> (use 'clojure.contrib.repl-utils) nil user=> (source zero?) (defn zero? "Returns true if num is zero, else false" {:tag Boolean :inline (fn [x] `(. clojure.lang.Numbers (isZero ~x)))} [x] (. clojure.lang.Numbers (isZero x))) using (zero? i) in dot: real 2m38.378s user 2m40.601s sys 0m1.875s real 2m30.614s user 2m33.081s sys 0m1.853s using (= 0 i) in dot: real 3m18.556s user 3m20.334s sys 0m2.060s real 3m20.425s user 3m23.392s sys 0m1.734s using (== 0 i) in dot: real 3m21.701s user 3m24.043s sys 0m1.982s real 3m22.441s user 3m24.420s sys 0m2.013s --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---