1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 10:07:45 +03:00
mal/perf.mal

28 lines
787 B
Plaintext
Raw Normal View History

(defmacro! time
(fn* (exp)
2015-02-09 09:23:10 +03:00
`(let* (start_FIXME (time-ms)
ret_FIXME ~exp)
(do
(prn (str "Elapsed time: " (- (time-ms) start_FIXME) " msecs"))
ret_FIXME))))
2015-02-28 19:38:17 +03:00
(def! run-fn-for*
(fn* [fn max-ms acc-ms iters]
(let* [start (time-ms)
_ (fn)
elapsed (- (time-ms) start)
new-iters (+ 1 iters)
new-acc-ms (+ acc-ms elapsed)]
;(do (prn "here:" new-acc-ms "/" max-ms "iters:" new-iters) )
(if (>= new-acc-ms max-ms)
(/ (* max-ms iters) new-acc-ms)
(run-fn-for* fn max-ms new-acc-ms new-iters)))))
(def! run-fn-for
(fn* [fn max-secs]
(do
;; Warm it up first
(run-fn-for* fn 1000 0 0)
;; Now do the test
(/ (run-fn-for* fn (* 1000 max-secs) 0 0) 3))))