help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with position and find (cl)


From: Florian Beck
Subject: Re: Problem with position and find (cl)
Date: Sat, 21 Jun 2008 00:31:14 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Barry Margolin <barmar@alum.mit.edu> writes:

> In article <87abhfg0mn.fsf@sophokles.streitblatt.de>,
>  Florian Beck <abstraktion@t-online.de> wrote:
>
>> Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:
>> 
>> 
>> > position default test is 'eq, try 'equal
>> 
>> Indeed, many cl-tests default to 'eq.
>> 
>> BTW, what is the reason for this (apart from being a language convention)?
>
> Just because things look similar doesn't mean they're the same.  Imagine 
> if you use a list like (firstname lastname) to represent people, and you 
> have two John Smiths in the group.

Yes, that was what I was trying to explain.

>> 
>> When I try
>> 
>> (let ((start-time (current-time)))
>>   (dotimes (i 1000000)
>>     (position '(1) '((2) (5) (2) 2 x  4 fer fer f r e wqf (1) fr r) :test 
>>     'eq))
>>   (format-time-string "%S" (time-since start-time)))
>> 
>> with 'eq and 'equal I get the same result. So 'eq is not more efficent,
>> is it?
>
> For a single-element list the difference is almost negligible.  Try 
> again with long lists, like 50 or 100 elements long.

I doesn't scale, but not that quickly:

(let ((start-time (current-time))
      (test-list (append (make-list 10000 'x) '((1)))))
  (dotimes (i 1000)
    (position '(1) test-list :test  'equal))
  (format"%.3f" (- (time-to-seconds  (current-time)) (time-to-seconds 
start-time) )))
      

(let ((start-time (current-time))
      (test-list (append (make-list 10000 'x) '((1)))))
  (dotimes (i 1000)
    (position '(1) test-list :test  'eq))
  (format "%.3f" (- (time-to-seconds  (current-time)) (time-to-seconds 
start-time) )))

This still takes more or less the same amount of time. (In my case 7.782s
and 7.689s.)

-- 
Florian Beck


reply via email to

[Prev in Thread] Current Thread [Next in Thread]