changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/lib/rt/bench.lisp

changeset 698: 96958d3eb5b0
parent: 0f0e5f9b5c55
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
1 ;;; lib/rt/bench.lisp --- Benchmarking Framework
2 
3 ;; This package provides an interface for benchmarking Lisp code.
4 
5 ;;; Code:
6 (in-package :rt/bench)
7 
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.")
10 
11 (defmacro bench (iter &body body)
12  `(loop for i from 1 to ,iter
13  do ,@body))
14 
15 (defmethod do-bench ((self test) &optional fx)
16  (declare (ignorable fx))
17  (with-test-env self
18  (flet ((%do ()
19  (if-let ((opt *compile-tests*))
20  (progn
21  (when (eq opt t) (setq opt *test-opts*))
22  ;; TODO 2023-09-21: handle failures here
23  (let ((fn (compile-test self :declare opt)))
24  (bench *bench-count* (funcall fn)))
25  (setf %test-result (make-test-result :pass (test-fn self))))
26  (progn
27  (bench *bench-count* (eval-test self))
28  (setf %test-result (make-test-result :pass (test-name self)))))))
29  (if *catch-test-errors*
30  (handler-bind
31  ((style-warning #'muffle-warning)
32  (error
33  #'(lambda (c)
34  (setf %test-bail t)
35  (setf %test-result (make-test-result :fail c))
36  (return-from %test-bail %test-result))))
37  (%do))
38  (%do)))))
39 
40 (defclass benchmark (test-object) ())
41 
42 (defmacro defbench (name props &body body)
43  "Define a BENCHMARK with NAME modulo PROPS with a benchmark-form of BODY.
44 
45 PROPS is a plist which accepts the following keywords:
46 
47 tbd"
48  nil)