diff --git a/devnotes/corelib.org b/devnotes/corelib.org index 00e57f7a85..b825ee8481 100644 --- a/devnotes/corelib.org +++ b/devnotes/corelib.org @@ -517,7 +517,7 @@ as macro * test * the-ns * thread-bound? -* TODO time +* DONE time * DONE to-array * TODO to-array-2d * DONE trampoline diff --git a/src/clj/cljs/core.clj b/src/clj/cljs/core.clj index ca99f5d7f8..de5225493e 100644 --- a/src/clj/cljs/core.clj +++ b/src/clj/cljs/core.clj @@ -635,3 +635,11 @@ "Creates and installs a new method of multimethod associated with dispatch-value. " [multifn dispatch-val & fn-tail] `(-add-method ~(with-meta multifn {:tag 'cljs.core.MultiFn}) ~dispatch-val (fn ~@fn-tail))) + +(defmacro time + "Evaluates expr and prints the time it took. Returns the value of expr." + [expr] + `(let [start# (.getTime (js/Date.) ()) + ret# ~expr] + (prn (str "Elapsed time: " (- (.getTime (js/Date.) ()) start#) " msecs")) + ret#))