Skip to content

Commit

Permalink
Add time macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
brentonashworth committed Sep 28, 2011
1 parent 418146c commit b216d0d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion devnotes/corelib.org
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ as macro
* test
* the-ns
* thread-bound?
* TODO time
* DONE time
* DONE to-array
* TODO to-array-2d
* DONE trampoline
Expand Down
8 changes: 8 additions & 0 deletions src/clj/cljs/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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#))

0 comments on commit b216d0d

Please sign in to comment.