forked from kanaka/mal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
perf.mal
27 lines (25 loc) · 787 Bytes
/
perf.mal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(defmacro! time
(fn* (exp)
`(let* (start_FIXME (time-ms)
ret_FIXME ~exp)
(do
(prn (str "Elapsed time: " (- (time-ms) start_FIXME) " msecs"))
ret_FIXME))))
(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))))