Created
July 18, 2013 17:04
-
-
Save gtrak/6031022 to your computer and use it in GitHub Desktop.
This file contains 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
(def ^:dynamic *times* nil) | |
(defmacro timek | |
"Evaluates expr and prints the time it took. Returns the value of | |
expr." | |
{:added "1.0"} | |
[k expr] | |
(let [plus (fn [val val2] (if val (+ val val2) val2))] | |
`(let [start# (. System (nanoTime)) | |
ret# ~expr | |
t# (/ (double (- (. System (nanoTime)) start#)) 1000000.0)] | |
(swap! *times* update-in [~k] ~plus t#) | |
ret#))) | |
(defmacro with-timek | |
[& body] | |
`(binding [*times* (atom {})] | |
~@body | |
(clojure.pprint/pprint @*times*))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment