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 15:56:57 -0400 Message-ID: References: <874mhvq3b2.fsf@mbork.pl> <8337xezpdc.fsf@gnu.org> <83vbaay4dd.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 1444766821 2576 80.91.229.3 (13 Oct 2015 20:07:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 13 Oct 2015 20:07:01 +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 22:06:54 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 1Zm5qT-0002t8-Jt for geh-help-gnu-emacs@m.gmane.org; Tue, 13 Oct 2015 22:06:49 +0200 Original-Received: from localhost ([::1]:39108 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zm5j2-0000NC-Op for geh-help-gnu-emacs@m.gmane.org; Tue, 13 Oct 2015 15:59:08 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57847) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zm5hc-0007cU-86 for help-gnu-emacs@gnu.org; Tue, 13 Oct 2015 15:57:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zm5hb-0008G2-2B for help-gnu-emacs@gnu.org; Tue, 13 Oct 2015 15:57:40 -0400 Original-Received: from mail-oi0-x233.google.com ([2607:f8b0:4003:c06::233]:33215) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zm5hZ-0008En-MV; Tue, 13 Oct 2015 15:57:37 -0400 Original-Received: by oiar126 with SMTP id r126so16173256oia.0; Tue, 13 Oct 2015 12:57:37 -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=sYLRzkc4fQzWgbWmI02UsfYfK5d1BvnfFgKX76aunF0=; b=c+TozB6pS/YhctMbvnipNIf1oVhb6RRx5hjLO5XlSJA+3SwpJOHozz3lAJqdkPCFJe lOCBQKdmwJq45j06iS6EhhVjraKmaxXQESqOqsKcnqUNRGuhs9pD8T1/duYeqneCJEdH 9Dfc3jYJNpy65G8/7+oTxsGQk5VJpYqAq8T/RZh62WDIhgTykNYMN3wIqT7mH8xVXTxS U2eNlNx1jRNMXQCXj2EDxEhDtKTNANhXRgnE7SeTjR44yObTQfj9BixBe6v8VQigO7f9 wKJc6CwyuwXLaaHMVQmPrcRLv/wgehsDgnY174QoG4IcMu4fOxiIWMV0bqC9sGjOxfpT ALmw== X-Received: by 10.202.215.136 with SMTP id o130mr19796159oig.85.1444766257060; Tue, 13 Oct 2015 12:57:37 -0700 (PDT) Original-Received: by 10.202.172.205 with HTTP; Tue, 13 Oct 2015 12:56:57 -0700 (PDT) In-Reply-To: <83vbaay4dd.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::233 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:107620 Archived-At: Thanks! 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 1000 executions of string-match-p approach took 0.047496 seconds 1000 executions of cl-count approach took 0.035816 seconds 1000 executions of cdr approach took 0.043535 seconds nil 1000 executions of string-match-p approach took 0.047068 seconds 1000 executions of cl-count approach took 0.035923 seconds 1000 executions of cdr approach took 0.043363 seconds nil 1000 executions of string-match-p approach took 0.047406 seconds 1000 executions of cl-count approach took 0.034490 seconds 1000 executions of cdr approach took 0.043718 seconds nil 1000 executions of string-match-p approach took 0.047117 seconds 1000 executions of cl-count approach took 0.035804 seconds 1000 executions of cdr approach took 0.043340 seconds nil 1000 executions of string-match-p approach took 0.208332 seconds 1000 executions of cl-count approach took 0.035798 seconds 1000 executions of cdr approach took 0.043902 seconds nil 1000 executions of string-match-p approach took 0.047357 seconds 1000 executions of cl-count approach took 0.035955 seconds 1000 executions of cdr approach took 0.043331 seconds nil -- Kaushal Modi On Tue, Oct 13, 2015 at 3:07 PM, Eli Zaretskii wrote: >> From: Kaushal Modi >> Date: Tue, 13 Oct 2015 13:43:05 -0400 >> Cc: Help Gnu Emacs mailing list >> >> I am, though, unable to quantify which approach is the fastest using >> `benchmark`. >> >> I ran the below wrapper progn block couple of times and I got >> different results each time. Oddly enough, I even got negative >> execution times. >> What am I doing wrong? > > Could be a bug in 'benchmark'. Just call float-time before and after, > and subtract the values, it should be good enough. >