Created
November 30, 2011 13:14
-
-
Save acardona/1409016 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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