Skip to content

Instantly share code, notes, and snippets.

@kbaribeau
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbaribeau/61f47c00efc5133eef54 to your computer and use it in GitHub Desktop.
Save kbaribeau/61f47c00efc5133eef54 to your computer and use it in GitHub Desktop.
simple clojure benchmarking
(defmacro bench [f]
`(let [start# (System/currentTimeMillis)
result# ~f
end# (System/currentTimeMillis)]
(println (str "bench result: " (- end# start#) "ms"))
result#))
@kbaribeau
Copy link
Author

=> (source time)
(defmacro time
  "Evaluates expr and prints the time it took.  Returns the value of
 expr."
  {:added "1.0"}
  [expr]
  `(let [start# (. System (nanoTime))
         ret# ~expr]
     (prn (str "Elapsed time: " (/ (double (- (. System (nanoTime)) start#)) 1000000.0) " msecs"))
     ret#))
nil

Suspiciously similar :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment