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

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

Re: return first element in list with certain property


From: James K. Lowden
Subject: Re: return first element in list with certain property
Date: Tue, 21 Nov 2017 22:52:16 -0500

On Tue, 21 Nov 2017 19:37:01 +0100
Michael Heerdegen <address@hidden> wrote:

> Philipp Stephani <address@hidden> writes:
> 
> > Please consider Knuth's statement about premature optimization.
> > Until your users have actually complained about the speed of your
> > product and you have benchmarked it and isolated cl-find-if as the
> > culprit, there's no need to micro-optimize. Presumably cl-find-if
> > has performed two iterations for years or decades without anybody
> > being bothered enough to improve it.
> 
> Not only that.  Seems the second iteration is at least ~50 times
> faster than the first one (using `elt' that is much faster than a
> loop), so it doesn't matter anyway.  If your program is slow, the
> second iteration will never be the culprit.

Not only that.  ;-)   Traversing the list twice is still O(n).  

I would guess in elisp the typical list is on the order of a dozen
elements.  As Rob Pike says,"Fancy algorithms are slow for small N, and
N is almost always small."  

 No matter how long the list is, it traversing it twice will only take
at most twice as long.  If your design fails when your data size
doubles, you have problems emacs won't solve.  

--jkl


reply via email to

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