Re: eql faster than = (integer comparison on sbcl)?
- From: krewinkel@xxxxxxx
- Date: 28 Feb 2007 09:14:36 -0800
On 28 Feb., 17:43, "Tim Bradshaw" <tfb+goo...@xxxxxxxx> wrote:
On Feb 28, 4:20 pm, krewin...@xxxxxxx wrote:
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.
If the compiler can make the right assumptions they should be compiled
into the same code. But it's not at all clear to me that it can - it
would have to know an awful lot about MEMBER to be able to do this.
It may well be that by the time the comparison predicate is called by
MEMBER, it knows nothing about the types, and = may then have to do
more work (check things actually are numbers, be prepared to signal an
error) than EQL.
But more to the point, the performance of your code will probably be
dominated by list traversal if N is not a fairly small number. You
need a better way of checking for duplicates. If you *really* care
about performance, I'd suggest:
if N is small allocate an N-element array of some good type (bit array
might be worth trying, else array of some immediate type). Use this
to know when you have dups. (try and allocate it on the stack...)
If N is large use a hashtable.
--tim
Thanks a lot Tim and André, that really helped me. Now, after you
explained it, the answer seems so obvious. N is rather small, so I
guess I'll use an array.
Thanks again,
Albert
.
- References:
- eql faster than = (integer comparison on sbcl)?
- From: krewinkel
- Re: eql faster than = (integer comparison on sbcl)?
- From: Tim Bradshaw
- eql faster than = (integer comparison on sbcl)?
- Prev by Date: Re: A style question
- Next by Date: Re: -2 is not a real number?!?
- Previous by thread: Re: eql faster than = (integer comparison on sbcl)?
- Index(es):
Relevant Pages
|