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

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

Re: [External] : Re: Testing whether a list contains at least one non-ni


From: Joost Kremers
Subject: Re: [External] : Re: Testing whether a list contains at least one non-nil element
Date: Tue, 25 Oct 2022 22:19:18 +0200
User-agent: mu4e 1.8.3; emacs 28.1.91

On Tue, Oct 25 2022, Drew Adams wrote:
>> > > I would like to test whether a list contains at least one
>> > > non-nil element? If I do that, then I would be able to
>> > > continue a loop where a non-nil element would mean
>> > > that a match was found.
>> >
>> > (seq-some (lambda (e) (not (null e))) mylist)
>> >
>> > or shorter:
>> >
>> > (not (seq-every-p #'null mylist))
>> 
>> How does your implementation (not (seq-every-p #'null mylist)) compared to
>> 
>> (elt (delq nil mylist) 0)
>
> `delq' is a "destructive" operation.

Oops, I didn't realise that when I wrote my reply... Should've checked...

So hopefully this gives a better idea:

```
(benchmark 100000 '(let ((mylist (list nil nil nil nil nil nil nil nil nil t)))
                     (elt (delq nil mylist) 0)))
"Elapsed time: 0.493742s (0.379511s in 2 GCs)"

(benchmark 100000 '(let ((mylist (list nil nil nil nil nil nil nil nil nil t)))
                     (not (seq-every-p #'null mylist))))
"Elapsed time: 0.923503s (0.566131s in 3 GCs)"


(benchmark 100000 '(let ((mylist (list nil t nil nil nil nil nil nil nil nil 
t)))
                     (elt (delq nil mylist) 0)))
"Elapsed time: 0.496120s (0.377506s in 2 GCs)"


(benchmark 100000 '(let ((mylist (list nil t nil nil nil nil nil nil nil nil 
t)))
                     (not (seq-every-p #'null mylist))))
"Elapsed time: 0.823751s (0.566227s in 3 GCs)"
```


-- 
Joost Kremers
Life has its moments



reply via email to

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