Skip to content

Instantly share code, notes, and snippets.

@timsgardner
Created December 9, 2014 04:04
Show Gist options
  • Select an option

  • Save timsgardner/472148b929d4407f8aa2 to your computer and use it in GitHub Desktop.

Select an option

Save timsgardner/472148b929d4407f8aa2 to your computer and use it in GitHub Desktop.
time-it
(defn time-it
"Signature slightly awkward to resemble that of time-it-mac"
([f] (time-it f 1))
([n f]
(. clojure.lang.RT (StartStopwatch))
(dotimes [_ n] (f))
(let [t (. clojure.lang.RT StopStopwatch)]
(/ t n))))
(defmacro time-it-mac
([n & body]
`(do
(. clojure.lang.RT (StartStopwatch))
(dotimes [_# ~n] ~@body)
(let [t# (. clojure.lang.RT StopStopwatch)]
(/ t# ~n)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment