Re: eql faster than = (integer comparison on sbcl)?
- From: André Thieme <address.good.until.2007.may.12@xxxxxxxxxxx>
- Date: Wed, 28 Feb 2007 17:37:52 +0100
krewinkel@xxxxxxx schrieb:
Hi,
I encountered the following strange behavior I don't understand: I
needed
to generate a random list of <n> unique integers with a maximum of
<max>. So I did the following:
(defun unique-random-ints (n max)
(declare (optimize (speed 3) (safety 0) (debug 0))
(type (unsigned-byte 16) n max))
(when (> n max) (error "n > max, can't create that many unique
integers"))
(let ((result nil))
(do ((i 0)
(j (random max) (random max)))
((= n i) result)
(declare (type (unsigned-byte 32) i j))
(unless (member j result :test #'=)
(progn (push j result)
(incf i))))))
It works fine with sbcl 1.0.1 (on linux i686), but it gets faster if
the :test #'= is replaced by #'eql. Why is that? Shouldn't the #'=
version be faster (since it's a more specific test)?
Any pointer would be appreciated.
Albert
What you saw is expected behaviour.
eql is more specific than =.
This is because = compares mathematical equality:
(= 1 1.0) => T
(eql 1 1.0) => NIL
1 is of type BIT while 1.0 is of type SINGLE-FLOAT.
André
--
.
- References:
- eql faster than = (integer comparison on sbcl)?
- From: krewinkel
- eql faster than = (integer comparison on sbcl)?
- Prev by Date: Re: A style question
- Next by Date: Re: eql faster than = (integer comparison on sbcl)?
- Previous by thread: eql faster than = (integer comparison on sbcl)?
- Next by thread: Re: eql faster than = (integer comparison on sbcl)?
- Index(es):
Relevant Pages
|