Evaluates expr and prints the time it took. Returns the value of
expr.
;; Time how long it takes to write a string to a file 100 times
(defn time-test []
(with-open [w (writer "test.txt" :append false)]
(dotimes [_ 100]
(.write w "I am being written to a file."))))
user=> (time (time-test))
"Elapsed time: 19.596371 msecs"
(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#))
Comments top
No comments for time. Log in to add a comment.