Last active
November 17, 2016 18:12
-
-
Save spacepluk/85b07e6eabb146e78c7fc02fb091057f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#?(:clj | |
(defmacro cljs? | |
[] | |
`(boolean (:ns '&env)))) | |
#?(:clj | |
(defn err-sym | |
[n] | |
(if n | |
`js/Error | |
`Throwable))) | |
#?(:clj | |
(defmacro profile | |
[label expr] | |
`(let [before# (default-timefn) | |
_# (swap! depth inc) | |
_# (println (indent ">>") ~label) | |
result# (try | |
~expr | |
(catch ~(err-sym (cljs?)) e# | |
e#)) | |
after# (default-timefn)] | |
(println (indent "<<") ~label "took" (- after# before#) "millis") | |
(swap! depth dec) | |
(if (instance? ~(err-sym (cljs?)) result#) | |
(throw result#) | |
result#)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment