This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-18
Channels
- # announcements (4)
- # babashka (13)
- # beginners (8)
- # chlorine-clover (1)
- # cider (5)
- # clj-http (12)
- # clojure (157)
- # clojure-dev (14)
- # clojure-europe (26)
- # clojure-nl (2)
- # clojure-norway (69)
- # clojure-uk (6)
- # clojuredesign-podcast (21)
- # clojurescript (7)
- # core-async (4)
- # datomic (170)
- # editors (1)
- # hyperfiddle (45)
- # java (7)
- # joyride (1)
- # leiningen (43)
- # lsp (7)
- # malli (24)
- # music (1)
- # off-topic (22)
- # pathom (16)
- # portal (31)
- # re-frame (1)
- # releases (1)
- # shadow-cljs (36)
- # squint (4)
hey all, I'm trying to create a macro to use in the Clojurescript side of my cljc library. Basically, it's a complete rip-off of cljs.core/simple-benchmark
but uses (js/performance.now)
instead of (.getTime (js/Date.))
. For some reason I can't get it to compile though. if I have the :cljs reader conditional, I get "benchmark does not exist" if I ditch the conditional I get things like "var bindings does not exist". And that does mean it exists in a cljc file of it's own.
#?(:cljs
(cljs.core/defmacro benchmark
[bindings expr iterations & {:keys [print-fn] :or {print-fn 'println}}]
(cljs.core/let [bs-str (pr-str bindings)
expr-str (pr-str expr)]
`(let ~bindings
(let [start# (js/performance.now)
ret# (dotimes [_# ~iterations] ~expr)
end# (js/performance.now)
elapsed# (- end# start#)]
(~print-fn (cljs.core/str ~bs-str ", " ~expr-str ", "
~iterations " runs, " elapsed# " msecs")))))))
I'd suggest moving the only platform dependent part into a helper function. so the macro just calls (get-timestamp)
or whatever and nothing host specific. then the macro becomes much easier and the rest you can solve via reader conditionals
That's funny I was just reading your blog post on the subject lol
Do you know if I need to qualify the symbols defmacro, let, and str like that ?