From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help Subject: Re: How to count the number of occurrences of a character in a string? Date: Tue, 13 Oct 2015 23:17:28 +0300 Message-ID: <83si5ey147.fsf@gnu.org> References: <874mhvq3b2.fsf@mbork.pl> <8337xezpdc.fsf@gnu.org> <83vbaay4dd.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1444767521 15888 80.91.229.3 (13 Oct 2015 20:18:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 13 Oct 2015 20:18:41 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 13 22:18:32 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Zm61n-00064M-Ck for geh-help-gnu-emacs@m.gmane.org; Tue, 13 Oct 2015 22:18:31 +0200 Original-Received: from localhost ([::1]:39164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zm61h-0005Ef-8N for geh-help-gnu-emacs@m.gmane.org; Tue, 13 Oct 2015 16:18:25 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39656) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zm60d-00054v-Iz for help-gnu-emacs@gnu.org; Tue, 13 Oct 2015 16:17:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zm60a-0002nV-CL for help-gnu-emacs@gnu.org; Tue, 13 Oct 2015 16:17:19 -0400 Original-Received: from mtaout25.012.net.il ([80.179.55.181]:39044) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zm60a-0002mu-4s for help-gnu-emacs@gnu.org; Tue, 13 Oct 2015 16:17:16 -0400 Original-Received: from conversion-daemon.mtaout25.012.net.il by mtaout25.012.net.il (HyperSendmail v2007.08) id <0NW600D00DFTN900@mtaout25.012.net.il> for help-gnu-emacs@gnu.org; Tue, 13 Oct 2015 23:14:46 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([84.94.185.246]) by mtaout25.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NW600CCNDKLV410@mtaout25.012.net.il> for help-gnu-emacs@gnu.org; Tue, 13 Oct 2015 23:14:46 +0300 (IDT) In-reply-to: X-012-Sender: halo1@inter.net.il X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 80.179.55.181 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:107621 Archived-At: > From: Kaushal Modi > Date: Tue, 13 Oct 2015 15:56:57 -0400 > Cc: Help Gnu Emacs mailing list > > Now I see some convergence in the results and this was the conclusion, > fastest to slowest > > 1. cl-count > 2. Eli's cdr approach > 3. My string-match-p approach > > Code: https://gist.github.com/ab487f63727381179f61 > Raw results: > > 1000 executions of string-match-p approach took 0.047036 seconds > 1000 executions of cl-count approach took 0.036476 seconds > 1000 executions of cdr approach took 0.043735 seconds > nil > 1000 executions of string-match-p approach took 0.046918 seconds > 1000 executions of cl-count approach took 0.035476 seconds > 1000 executions of cdr approach took 0.202394 seconds > nil Looks like 1000 loops is too few: your measurements hit clock quantization error, and also some background activities affect the results. I suggest to try 10000 iterations. Also, did you actually try 'mapc', per my second suggestion?