[Openmcl-devel] To sqrt or to expt, that is the question
Gary King
gwking at cs.umass.edu
Mon Dec 22 17:52:44 PST 2003
I was looking at some code where someone had used expt to compute the
square root of a number. "Hmm, I thought, it all depends on the
compiler and the implementation, but I would have thought that (sqrt x)
would be faster than (expt x 0.5)." So I tried the following,
admittedly unscientific, test:
(time
(let ((x 0d0))
(loop repeat 100000 do
(setf x (expt 101 0.5)))
x))
(time
(let ((x 0d0))
(loop repeat 100000 do
(setf x (sqrt 101)))
x))
To my surprise in both MCL and OpenMCL, not only was expt faster, but
sqrt conses. Note that I tried the same test in SBCL and found that
there was no significant difference between expt and sqrt. This
probably isn't a big deal, but it might be worth optimizing sqrt in MCL
at some point...
--
Gary Warren King, Lab Manager
EKSL East, University of Massachusetts * 413 577 0176
"no art, however minor, demands less than total dedication if you want
to excel in it."
-- Alberti
More information about the Openmcl-devel
mailing list