Skip to content

Instantly share code, notes, and snippets.

@karansag
karansag / gist:bab7ea1a4613dfd929ea
Last active August 29, 2015 14:18
Dynamically Parallel Sequence Operations (Map as an Example)
(defn avg [xs] (/ (apply + xs) (count xs)))
(defn timed
"Returns a function returning a two element vector with the execution time of f
as the first element and the original result as the second"
[f]
(fn [& args]
(let [start (. System (nanoTime))
res (apply f args)]
> [(/ (double (- (. System (nanoTime)) start)) 1000000.0) res])))
(defn timed-sink