Skip to content

Instantly share code, notes, and snippets.

@spacepluk
Last active November 17, 2016 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spacepluk/85b07e6eabb146e78c7fc02fb091057f to your computer and use it in GitHub Desktop.
Save spacepluk/85b07e6eabb146e78c7fc02fb091057f to your computer and use it in GitHub Desktop.
#?(: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