[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: return first element in list with certain property
From: |
Eric Abrahamsen |
Subject: |
Re: return first element in list with certain property |
Date: |
Mon, 20 Nov 2017 14:02:05 -0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Emanuel Berg <moasen@zoho.com> writes:
> Eric Abrahamsen wrote:
>
>> FWIW, this is essentially how seq-find works,
>> and I generally use this.
>
> Here (my use case) it is important that the
> search is linear along the list from the
> beginning as the hit is almost always in the
> very early section of the list.
In that case there will be less difference between the two: as Drew
noted, `cl-find-if' will traverse the list twice, which only becomes a
big problem if the desired element is at the end of the list.
But enough speculation!
(setq test-front (append '(1 1 3) (make-list 1000 1)))
(setq test-back (append (make-list 1000 1) '(3 1 1)))
(benchmark 1000 '(seq-find (lambda (elt) (= 3 elt)) test-front))
"Elapsed time: 0.008247s"
(benchmark 1000 '(cl-find-if (lambda (elt) (= 3 elt)) test-front))
"Elapsed time: 0.006165s"
(benchmark 1000 '(seq-find (lambda (elt) (= 3 elt)) test-back))
"Elapsed time: 0.134623s"
(benchmark 1000 '(cl-find-if (lambda (elt) (= 3 elt)) test-back))
"Elapsed time: 0.167007s"
Yup, in your case it doesn't matter too much.
Eric
- Re: return first element in list with certain property, (continued)
- Re: return first element in list with certain property, Emanuel Berg, 2017/11/19
- Re: return first element in list with certain property, John Mastro, 2017/11/20
- Re: return first element in list with certain property, Michael Heerdegen, 2017/11/20
- Re: return first element in list with certain property, Emanuel Berg, 2017/11/20
- Re: return first element in list with certain property, John Mastro, 2017/11/20
- Re: return first element in list with certain property, Michael Heerdegen, 2017/11/20
- Re: return first element in list with certain property, Emanuel Berg, 2017/11/20
RE: return first element in list with certain property, Drew Adams, 2017/11/20
- Re: return first element in list with certain property, Eric Abrahamsen, 2017/11/20
- Re: return first element in list with certain property, Emanuel Berg, 2017/11/20
- Re: return first element in list with certain property,
Eric Abrahamsen <=
- Re: return first element in list with certain property, Emanuel Berg, 2017/11/20
- Re: return first element in list with certain property, Emanuel Berg, 2017/11/20
- Re: return first element in list with certain property, Michael Heerdegen, 2017/11/21
- Re: return first element in list with certain property, Emanuel Berg, 2017/11/21
- Re: return first element in list with certain property, Michael Heerdegen, 2017/11/21
- Re: return first element in list with certain property, Nicolas Petton, 2017/11/22
Re: return first element in list with certain property, Nicolas Petton, 2017/11/22
Re: return first element in list with certain property, Philipp Stephani, 2017/11/21
Re: return first element in list with certain property, Michael Heerdegen, 2017/11/21
RE: return first element in list with certain property, Drew Adams, 2017/11/21