1 ;;;; FIXME: This should probably move to some separate tests or benchmarks
6 (declaim (optimize (speed 3) (safety 0) (compilation-speed 0)))
11 (defvar m (car (generic-function-methods #'shared-initialize)))
12 (defvar gf #'shared-initialize)
13 (defvar c (find-class 'standard-class))
16 ((slot :initform nil :reader str-slot))
17 (:metaclass structure-class))
19 (defvar str (make-instance 'str))
21 (push (cons "Time unoptimized slot-value. This is case (1) from notes.text. (standard)"
22 '(time-slot-value m 'plist 10000))
24 (push (cons "Time unoptimized slot-value. This is case (1) from notes.text. (standard)"
25 '(time-slot-value m '%generic-function 10000))
27 (push (cons "Time unoptimized slot-value. This is case (1) from notes.text. (structure)"
28 '(time-slot-value str 'slot 10000))
30 (defun time-slot-value (object slot-name n)
31 (time (dotimes-fixnum (i n) (slot-value object slot-name))))
33 (push (cons "Time optimized slot-value outside of a defmethod. Case (2). (standard)"
34 '(time-slot-value-function m 10000))
36 (defun time-slot-value-function (object n)
37 (time (dotimes-fixnum (i n) (slot-value object '%function))))
39 (push (cons "Time optimized slot-value outside of a defmethod. Case (2). (structure)"
40 '(time-slot-value-slot str 10000))
42 (defun time-slot-value-slot (object n)
43 (time (dotimes-fixnum (i n) (slot-value object 'slot))))
45 (push (cons "Time one-class dfun."
46 '(time-generic-function-methods gf 10000))
48 (defun time-generic-function-methods (object n)
49 (time (dotimes-fixnum (i n) (generic-function-methods object))))
51 (push (cons "Time one-index dfun."
52 '(time-class-precedence-list c 10000))
54 (defun time-class-precedence-list (object n)
55 (time (dotimes-fixnum (i n) (class-precedence-list object))))
57 (push (cons "Time n-n dfun."
58 '(time-method-function m 10000))
60 (defun time-method-function (object n)
61 (time (dotimes-fixnum (i n) (method-function object))))
63 (push (cons "Time caching dfun."
64 '(time-class-slots c 10000))
66 (defun time-class-slots (object n)
67 (time (dotimes-fixnum (i n) (class-slots object))))
69 (push (cons "Time typep for classes."
70 '(time-typep-standard-object m 10000))
72 (defun time-typep-standard-object (object n)
73 (time (dotimes-fixnum (i n) (typep object 'standard-object))))
75 (push (cons "Time default-initargs."
76 '(time-default-initargs (find-class 'plist-mixin) 1000))
78 (defun time-default-initargs (class n)
79 (time (dotimes-fixnum (i n) (default-initargs class nil))))
81 (push (cons "Time make-instance."
82 '(time-make-instance (find-class 'plist-mixin) 1000))
84 (defun time-make-instance (class n)
85 (time (dotimes-fixnum (i n) (make-instance class))))
87 (push (cons "Time constant-keys make-instance."
88 '(time-constant-keys-make-instance 1000))
91 (expanding-make-instance-toplevel
92 (defun constant-keys-make-instance (n)
93 (dotimes-fixnum (i n) (make-instance 'plist-mixin))))
95 (precompile-random-code-segments)
97 (defun time-constant-keys-make-instance (n)
98 (time (constant-keys-make-instance n)))
100 (defun expand-all-macros (form)
101 (walk-form form nil (lambda (form context env)
102 (if (and (eq context :eval)
105 (not (special-form-p (car form)))
106 (macro-function (car form)))
107 (values (macroexpand form env))
110 (push (cons "Macroexpand meth-structure-slot-value"
111 '(pprint (multiple-value-bind (pgf pm)
112 (prototypes-for-make-method-lambda
113 'meth-structure-slot-value)
115 'meth-structure-slot-value pgf pm
117 '((lambda () (slot-value object 'slot)))
121 (push (cons "Show code for slot-value inside a defmethod for a structure-class. Case (3)."
122 '(disassemble (meth-structure-slot-value str)))
124 (defmethod meth-structure-slot-value ((object str))
125 (lambda () (slot-value object 'slot)))
127 #|| ; interesting, but long. (produces 100 lines of output)
128 (push (cons "Macroexpand meth-standard-slot-value"
129 '(pprint (expand-all-macros
130 (expand-defmethod-internal 'meth-standard-slot-value
131 nil '((object standard-method))
132 '((lambda () (slot-value object '%function)))
135 (push (cons "Show code for slot-value inside a defmethod for a standard-class. Case (4)."
136 '(disassemble (meth-standard-slot-value m)))
138 (defmethod meth-standard-slot-value ((object standard-method))
139 (lambda () (slot-value object '%function)))
143 (dolist (doc+form (reverse *tests*))
144 (format t "~&~%~A~%" (car doc+form))
145 (pprint (cdr doc+form))
146 (eval (cdr doc+form))))