1
1
mirror of https://github.com/kanaka/mal.git synced 2024-10-05 18:08:55 +03:00
mal/impls/lib/benchmark.mal
2021-05-31 10:28:04 -05:00

16 lines
432 B
Plaintext

;; An alternative approach, to complement perf.mal
(load-file "../lib/load-file-once.mal")
(load-file-once "../lib/trivial.mal") ; gensym inc
(def! benchmark* (fn* [f n results]
(if (< 0 n)
(let* [start-ms (time-ms)
_ (f)
end-ms (time-ms)]
(benchmark* f (- n 1) (conj results (- end-ms start-ms))))
results)))
(defmacro! benchmark (fn* [expr n]
`(benchmark* (fn* [] ~expr) ~n [])))