babashka/test-resources/lib_tests/portal/bench.cljc
Gabriel Horner 78a05139cb Add a number of library tests from projects.md
Also add more docs around adding test libs and tweak add script
2021-12-28 09:23:37 -05:00

18 lines
625 B
Clojure

(ns portal.bench
#?(:cljs (:refer-clojure :exclude [simple-benchmark]))
#?(:cljs (:require-macros portal.bench)))
(defn now []
#?(:clj (System/currentTimeMillis)
:cljs (.now js/Date)))
(defmacro simple-benchmark
[bindings expr iterations & {:keys [print-fn] :or {print-fn 'println}}]
(let [expr-str (pr-str expr)]
`(let ~bindings
(dotimes [_# ~iterations] ~expr)
(let [start# (now)
ret# (dotimes [_# ~iterations] ~expr)
end# (now)
elapsed# (- end# start#)]
(~print-fn (str ~iterations " runs, " elapsed# " msecs, " ~expr-str))))))