Created
December 27, 2014 21:45
-
-
Save timsgardner/774a106aabd73d4b8520 to your computer and use it in GitHub Desktop.
invocation cost
This file contains hidden or 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
(ns invocation-cost) | |
(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))))) | |
(def bla :bla) | |
(defn simpler [] | |
bla) | |
(defn stress [] | |
[(let [f simpler] | |
(time-it-mac 100000 | |
(f))) | |
(time-it-mac 100000 | |
bla)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment