Re: eql faster than = (integer comparison on sbcl)?



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é
--
.



Relevant Pages

  • eql faster than = (integer comparison on sbcl)?
    ... I encountered the following strange behavior I don't understand: ... to generate a random list of unique integers with a maximum of ... It works fine with sbcl 1.0.1 (on linux i686), ...
    (comp.lang.lisp)
  • Re: eql faster than = (integer comparison on sbcl)?
    ... I encountered the following strange behavior I don't understand: ... to generate a random list of unique integers with a maximum of ... For other equality predicates, the underlying test code is ...
    (comp.lang.lisp)