1.0.16.30: couple of small Darwin cleanups
[sbcl/pkhuong.git] / src / pcl / time.lisp
blobb7a4e95e68be3627a52fbf7367adc04a38973a0a
1 ;;;; FIXME: This should probably move to some separate tests or benchmarks
2 ;;;; directory.
4 (in-package "SB-PCL")
6 (declaim (optimize (speed 3) (safety 0) (compilation-speed 0)))
8 (defvar *tests*)
9 (setq *tests* nil)
11 (defvar m (car (generic-function-methods #'shared-initialize)))
12 (defvar gf #'shared-initialize)
13 (defvar c (find-class 'standard-class))
15 (defclass str ()
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))
23 *tests*)
24 (push (cons "Time unoptimized slot-value. This is case (1) from notes.text. (standard)"
25 '(time-slot-value m '%generic-function 10000))
26 *tests*)
27 (push (cons "Time unoptimized slot-value. This is case (1) from notes.text. (structure)"
28 '(time-slot-value str 'slot 10000))
29 *tests*)
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))
35 *tests*)
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))
41 *tests*)
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))
47 *tests*)
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))
53 *tests*)
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))
59 *tests*)
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))
65 *tests*)
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))
71 *tests*)
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))
77 *tests*)
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))
83 *tests*)
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))
89 *tests*)
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)
103 (consp form)
104 (symbolp (car form))
105 (not (special-form-p (car form)))
106 (macro-function (car form)))
107 (values (macroexpand form env))
108 form))))
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)
114 (expand-defmethod
115 'meth-structure-slot-value pgf pm
116 nil '((object str))
117 '((lambda () (slot-value object 'slot)))
118 nil))))
119 *tests*)
121 (push (cons "Show code for slot-value inside a defmethod for a structure-class. Case (3)."
122 '(disassemble (meth-structure-slot-value str)))
123 *tests*)
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)))
133 nil))))
134 *tests*)
135 (push (cons "Show code for slot-value inside a defmethod for a standard-class. Case (4)."
136 '(disassemble (meth-standard-slot-value m)))
137 *tests*)
138 (defmethod meth-standard-slot-value ((object standard-method))
139 (lambda () (slot-value object '%function)))
142 (defun run-tests ()
143 (dolist (doc+form (reverse *tests*))
144 (format t "~&~%~A~%" (car doc+form))
145 (pprint (cdr doc+form))
146 (eval (cdr doc+form))))