Skip to content

Instantly share code, notes, and snippets.

@acardona
Created November 30, 2011 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acardona/1409016 to your computer and use it in GitHub Desktop.
Save acardona/1409016 to your computer and use it in GitHub Desktop.
(ns my.numeric.test)
(def a (ref nil))
(defn ^double sum
[^double a
^double b]
(+ a b))
(defn w1
[n]
(reduce sum (take n (repeatedly rand))))
(defn w1
[n]
(reduce + (take n (repeatedly rand))))
(defn w3
[^long n]
(loop [i (long 0)
sum (double 0)]
(if (< i n)
(recur (inc i) (+ sum (rand))))))
(println "w1:")
(dotimes [i 5]
(time (w1 300000)))
(println "w2:")
(dotimes [i 5]
(time (w2 300000)))
(println "w3:")
(dotimes [i 5]
(time (w3 300000)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment