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 (n)
79 (time (dotimes-fixnum (i n
) (default-initargs nil 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 (eq context
:eval
)
103 (values (%macroexpand form env
))
106 (push (cons "Macroexpand meth-structure-slot-value"
107 '(pprint (multiple-value-bind (pgf pm
)
108 (prototypes-for-make-method-lambda
109 'meth-structure-slot-value
)
111 'meth-structure-slot-value pgf pm
113 '((lambda () (slot-value object
'slot
)))
117 (push (cons "Show code for slot-value inside a defmethod for a structure-class. Case (3)."
118 '(disassemble (meth-structure-slot-value str
)))
120 (defmethod meth-structure-slot-value ((object str
))
121 (lambda () (slot-value object
'slot
)))
123 #||
; interesting, but long. (produces 100 lines of output)
124 (push (cons "Macroexpand meth-standard-slot-value"
125 '(pprint (expand-all-macros
126 (expand-defmethod-internal 'meth-standard-slot-value
127 nil
'((object standard-method
))
128 '((lambda () (slot-value object
'%function
)))
131 (push (cons "Show code for slot-value inside a defmethod for a standard-class. Case (4)."
132 '(disassemble (meth-standard-slot-value m
)))
134 (defmethod meth-standard-slot-value ((object standard-method
))
135 (lambda () (slot-value object
'%function
)))
139 (dolist (doc+form
(reverse *tests
*))
140 (format t
"~&~%~A~%" (car doc
+form
))
141 (pprint (cdr doc
+form
))
142 (eval (cdr doc
+form
))))