From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "James K. Lowden" Newsgroups: gmane.emacs.help Subject: Re: return first element in list with certain property Date: Tue, 21 Nov 2017 22:52:16 -0500 Organization: http://www.NewsDemon.com Message-ID: <20171121225216.17011915608ecbb6021c9bc2@speakeasy.net> References: <8660a60zjn.fsf@zoho.com> <87mv3gzndx.fsf@ericabrahamsen.net> <86ine4y7jy.fsf@zoho.com> <874lpozk0y.fsf@ericabrahamsen.net> <8660a4xuou.fsf@zoho.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1511322931 3156 195.159.176.226 (22 Nov 2017 03:55:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 22 Nov 2017 03:55:31 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 22 04:55:28 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHM8D-0000QK-7s for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Nov 2017 04:55:25 +0100 Original-Received: from localhost ([::1]:37679 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHM8K-0007Nm-G1 for geh-help-gnu-emacs@m.gmane.org; Tue, 21 Nov 2017 22:55:32 -0500 X-Received: by 10.107.88.11 with SMTP id m11mr10035021iob.18.1511322736855; Tue, 21 Nov 2017 19:52:16 -0800 (PST) Original-Path: usenet.stanford.edu!i6no3279049itb.0!news-out.google.com!x87ni1547ita.0!nntp.google.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!post01.iad!fx35.iad.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help X-Newsreader: Sylpheed 3.4.3 (GTK+ 2.24.28; x86_64--netbsd) Original-Lines: 28 Original-X-Complaints-To: abuse@newsdemon.com Original-NNTP-Posting-Date: Wed, 22 Nov 2017 03:52:16 UTC X-Received-Bytes: 2270 X-Received-Body-CRC: 3537126126 Original-Xref: usenet.stanford.edu gnu.emacs.help:220937 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:115047 Archived-At: On Tue, 21 Nov 2017 19:37:01 +0100 Michael Heerdegen wrote: > Philipp Stephani 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