Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns lazier.bench
- (:use clojure.core
- [clojure.contrib.str-utils :only (re-sub str-join)]
- clojure.contrib.pprint))
- (defn slow-computation [& more]
- (Thread/sleep 500)
- (if (seq more) more 1))
- (defmacro benchmark
- [functions lst]
- (println ";" (str-join "" (repeat 72 \=)))
- (pprint `~lst)
- (letfn [(make-fragment [f] `(~f ~lst))]
- `(do
- ~@(loop [functions functions timers []]
- (if (seq functions)
- (recur (rest functions)
- (cons `(do
- (print ";" (quote ~(first functions)) ": ")
- (time ~(make-fragment (first functions)))
- nil)
- timers))
- timers))
- (println))))
Add Comment
Please, Sign In to add comment