From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kaushal Modi Newsgroups: gmane.emacs.help Subject: Re: How to count the number of occurrences of a character in a string? Date: Tue, 13 Oct 2015 16:41:13 -0400 Message-ID: References: <874mhvq3b2.fsf@mbork.pl> <8337xezpdc.fsf@gnu.org> <83vbaay4dd.fsf@gnu.org> <83si5ey147.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1444770006 28578 80.91.229.3 (13 Oct 2015 21:00:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 13 Oct 2015 21:00:06 +0000 (UTC) Cc: Help Gnu Emacs mailing list To: Eli Zaretskii Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 13 23:00:05 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 1Zm6fu-0006lS-Uo for geh-help-gnu-emacs@m.gmane.org; Tue, 13 Oct 2015 22:59:59 +0200 Original-Received: from localhost ([::1]:39322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zm6ft-00012Z-Vf for geh-help-gnu-emacs@m.gmane.org; Tue, 13 Oct 2015 16:59:57 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53545) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zm6Oe-00083f-0t for help-gnu-emacs@gnu.org; Tue, 13 Oct 2015 16:42:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zm6OR-0000Nt-6M for help-gnu-emacs@gnu.org; Tue, 13 Oct 2015 16:41:56 -0400 Original-Received: from mail-oi0-x22e.google.com ([2607:f8b0:4003:c06::22e]:33717) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zm6OP-0000MB-LM; Tue, 13 Oct 2015 16:41:53 -0400 Original-Received: by oiar126 with SMTP id r126so16854899oia.0; Tue, 13 Oct 2015 13:41:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=4F+bPJR00fTj4pfTVXx5u1LcVgeiPmsEQPYB25BhB7g=; b=nBtfjnPXE5KC78EreQ2uw28J5jZa3v5m+fXd9/l7qhvB7l5I8M1YwcIh1Jc+OY0put Hrk1vq4QTWiN2Del79gDrD78vShIFDpOUtrfwZdvCZyHmo52/Ia1skD+TYKSl5M+frW9 yfj/9zp8HQLJl/Wdhp34BhOvyEqIcLDsWwfGVLEqeaD5oXbTeEKUrCqHO/cgiflVPahe qgeuyxBq+S3vbS+2t/ZZD2JXcGxa52ESwd85VbZL04xtCGWkkA9zGi9cFNkAHHWlizkh R1WORIWAX4hRZu2nhaUGLA69qDbbnnI4pta0jYPQbNKUGaEzJ4wEUYPhNv0+NFA4/Rak Xpwg== X-Received: by 10.202.211.10 with SMTP id k10mr19917488oig.34.1444768913120; Tue, 13 Oct 2015 13:41:53 -0700 (PDT) Original-Received: by 10.202.172.205 with HTTP; Tue, 13 Oct 2015 13:41:13 -0700 (PDT) In-Reply-To: <83si5ey147.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c06::22e 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:107625 Archived-At: Just tried that, mapc is the best alternative after cl-count. Updated the results and code at https://gist.github.com/kaushalmodi/ab487f63727381179f61 -- Kaushal Modi On Tue, Oct 13, 2015 at 4:17 PM, Eli Zaretskii wrote: >> 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? >