You're viewing version 1.2.0 of time. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16
  • (time expr)
Evaluates expr and prints the time it took. Returns the value of
expr.

4 Examples top

  • user> (time (Thread/sleep 100))
    "Elapsed time: 100.284772 msecs"
    nil
  • ;when working with lazy seqs
    (time (doall (...)))
  • ;; 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"
  • user=> (time (Thread/sleep 1000))
    "Elapsed time: 1000.267483 msecs"
    nil
    user=> (with-out-str (time (Thread/sleep 1000)))
    "\"Elapsed time: 1010.12942 msecs\"\n"
    
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:2959 top

(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#))
Vars in clojure.core/time: defmacro - / apply concat double let list prn seq str vector
Used in 0 other vars

Comments top

No comments for time. Log in to add a comment.