1 ;;;; -*- Mode: lisp -*-
3 ;;;; Copyright (c) 2007 Raymond Toy
5 ;;;; Permission is hereby granted, free of charge, to any person
6 ;;;; obtaining a copy of this software and associated documentation
7 ;;;; files (the "Software"), to deal in the Software without
8 ;;;; restriction, including without limitation the rights to use,
9 ;;;; copy, modify, merge, publish, distribute, sublicense, and/or sell
10 ;;;; copies of the Software, and to permit persons to whom the
11 ;;;; Software is furnished to do so, subject to the following
14 ;;;; The above copyright notice and this permission notice shall be
15 ;;;; included in all copies or substantial portions of the Software.
17 ;;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ;;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 ;;;; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 ;;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 ;;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 ;;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 ;;;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 ;;;; OTHER DEALINGS IN THE SOFTWARE.
27 ;;; Some simple timing tests
30 (defun time-add (&optional
(n 100000))
34 (declare (double-float sum
)
38 (setf sum
(cl:+ sum
1d0
)))
41 (let ((sum (qdi::make-qd-d
0d0
))
42 (one (qdi::make-qd-d
1d0
)))
43 (declare (type qdi
::%quad-double sum
)
47 (setf sum
(add-qd sum one
)))
51 (declare (type qd-real sum
)
55 (setf sum
(+ sum
#q1
)))
57 (format t
"Add double-floats ~d times~%" n
)
58 #+cmu
(ext:gc
:full t
)
60 (format t
"Add %quad-double (internal) ~d times~%" n
)
61 #+cmu
(ext:gc
:full t
)
63 (format t
"Add QD-REAL (method) ~d times~%" n
)
64 #+cmu
(ext:gc
:full t
)
68 (defun time-mul (&optional
(n 100000))
72 (declare (double-float sum
)
76 (setf sum
(cl:* sum
1d0
)))
79 (let ((sum (qdi::make-qd-d
0d0
))
80 (one (qdi::make-qd-d
1d0
)))
81 (declare (type qdi
::%quad-double sum
)
85 (setf sum
(mul-qd sum one
)))
89 (declare (type qd-real sum
)
93 (setf sum
(* sum
#q1
)))
95 (format t
"Multiply double-floats ~d times~%" n
)
96 #+cmu
(ext:gc
:full t
)
98 (format t
"Multiply %quad-double (internal) ~d times~%" n
)
99 #+cmu
(ext:gc
:full t
)
101 (format t
"Multiply QD-REAL (method) ~d times~%" n
)
102 #+cmu
(ext:gc
:full t
)
105 (defun time-div (&optional
(n 100000))
107 (flet ((div-double ()
109 (declare (double-float sum
)
110 (optimize (speed 3)))
113 (setf sum
(cl:/ sum
1d0
)))
116 (let ((sum (qdi::make-qd-d
7d0
))
117 (one (qdi::make-qd-d
1d0
)))
118 (declare (type qdi
::%quad-double sum
)
119 (optimize (speed 3)))
122 (setf sum
(div-qd sum one
)))
126 (declare (type qd-real sum
)
127 (optimize (speed 3)))
130 (setf sum
(/ sum
#q1
)))
132 (format t
"Divide double-floats ~d times~%" n
)
133 #+cmu
(ext:gc
:full t
)
135 (format t
"Divide %quad-double (internal) ~d times~%" n
)
136 #+cmu
(ext:gc
:full t
)
138 (format t
"Divide QD-REAL (method) ~d times~%" n
)
139 #+cmu
(ext:gc
:full t
)
142 (defun time-sqrt (&optional
(n 100000))
144 (flet ((sqrt-double ()
146 (declare (double-float sum
)
147 (optimize (speed 3)))
150 (setf sum
(cl:sqrt sum
)))
153 (let ((sum (qdi::make-qd-d
7d0
)))
154 (declare (type qdi
::%quad-double sum
)
155 (optimize (speed 3)))
158 (setf sum
(sqrt-qd sum
)))
162 (declare (type qd-real sum
)
163 (optimize (speed 3)))
166 (setf sum
(sqrt sum
)))
168 (format t
"Sqrt double-floats ~d times~%" n
)
169 #+cmu
(ext:gc
:full t
)
171 (format t
"Sqrt %quad-double (internal) ~d times~%" n
)
172 #+cmu
(ext:gc
:full t
)
174 (format t
"Sqrt QD-REAL (method) ~d times~%" n
)
175 #+cmu
(ext:gc
:full t
)
176 (time (sqrt-qd-real))))