Guest User

Untitled

a guest
Jul 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. (ns lazier.bench
  2. (:use clojure.core
  3. [clojure.contrib.str-utils :only (re-sub str-join)]
  4. clojure.contrib.pprint))
  5.  
  6. (defn slow-computation [& more]
  7. (Thread/sleep 500)
  8. (if (seq more) more 1))
  9.  
  10. (defmacro benchmark
  11. [functions lst]
  12. (println ";" (str-join "" (repeat 72 \=)))
  13. (pprint `~lst)
  14. (letfn [(make-fragment [f] `(~f ~lst))]
  15. `(do
  16. ~@(loop [functions functions timers []]
  17. (if (seq functions)
  18. (recur (rest functions)
  19. (cons `(do
  20. (print ";" (quote ~(first functions)) ": ")
  21. (time ~(make-fragment (first functions)))
  22. nil)
  23. timers))
  24. timers))
  25. (println))))
Add Comment
Please, Sign In to add comment