working on a generics approach for numerical testing.
[CommonLispStat.git] / external / clem / benchmark / benchmarks.lisp
blob25aa44735926c311ddc5f08045d36bd1b3c9bb51
2 (in-package :clem-benchmark)
4 (defmacro with-benchmark (&body body)
5 (let ((start-var (gensym))
6 (end-var (gensym)))
7 `(let ((,start-var (get-internal-run-time)))
8 (values
9 (multiple-value-list
10 (progn ,@body))
11 (let ((,end-var (get-internal-run-time)))
12 (coerce (/ (- ,end-var ,start-var) internal-time-units-per-second)
13 'double-float))))))
15 (defmacro benchmark-time (benchmark-results)
16 `(nth-value 1 ,benchmark-results))
18 (defparameter *matrix-benchmark-times* (make-hash-table :test 'eql))
20 (defmacro with-matrix-benchmark ((key) &body body)
21 (let ((time-sym (gensym))
22 (results-sym (gensym)))
23 `(multiple-value-bind (,results-sym ,time-sym)
24 (with-benchmark
25 (progn ,@body))
26 (setf (gethash ,key *matrix-benchmark-times*)
27 ,time-sym)
28 (values-list ,results-sym))))
30 (defun get-benchmark-time (key)
31 (gethash key *matrix-benchmark-times*))
33 (defun list-benchmarks ()
34 (let ((l))
35 (maphash #'(lambda (k v)
36 (push (cons k v) l))
37 *matrix-benchmark-times*)
38 (nreverse l)))
40 (defun clear-benchmarks ()
41 (clrhash *matrix-benchmark-times*))