Coverage report: /home/ellis/comp/core/lib/rt/bench.lisp
Kind | Covered | All | % |
expression | 0 | 62 | 0.0 |
branch | 0 | 0 | nil |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;; lib/rt/bench.lisp --- Benchmarking Framework
3
;; This package provides an interface for benchmarking Lisp code.
8
(defvar *bench-count* 10 "Default number of iterations to repeat a bench test for. This value is
9
used when the slot value of :BENCH is t.")
11
(defmacro time-total (n &body body)
12
"N-average the execution time of BODY in seconds"
13
(declare (optimize (speed 0)))
14
(with-gensyms (start end)
17
(setf ,start (get-internal-real-time))
20
(setf ,end (get-internal-real-time))
21
(coerce (/ (- ,end ,start) internal-time-units-per-second)
24
(defmacro bench (iter &body body)
25
`(loop for i from 1 to ,iter
28
(defmethod do-bench ((self test) &optional fx)
29
(declare (ignorable fx))
33
(with-compilation-unit (:override t :policy (or (and *test-suite* (test-policy *test-suite*)) *test-policy*))
34
;; TODO 2023-09-21: handle failures here
35
(let ((fn (compile-test self :declare (test-declare self))))
36
(bench *bench-count* (funcall fn)))
37
(setf %test-result (make-test-result :pass (test-fn self))))
39
(bench *bench-count* (eval-test self))
40
(setf %test-result (make-test-result :pass (name self)))))))
41
(if *catch-test-errors*
43
((style-warning #'muffle-warning)
47
(setf %test-result (make-test-result :fail c))
48
(return-from %test-bail %test-result))))
52
(defmethod do-bench ((self t) &optional fx)
53
(declare (ignorable fx))
54
(when-let ((test (find-test *test-suite* self)))
57
(defclass benchmark (test-object) ())
59
(defmacro defbench (name props &body body)
60
"Define a BENCHMARK with NAME modulo PROPS with a benchmark-form of BODY.
62
PROPS is a plist which accepts the following keywords: