From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: How to count the number of occurrences of a character in a string? Date: 13 Oct 2015 22:44:58 GMT Message-ID: References: <874mhvq3b2.fsf@mbork.pl> <8337xezpdc.fsf@gnu.org> <83vbaay4dd.fsf@gnu.org> <87wpuqxzrx.fsf@ul.ie> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1444776398 8105 80.91.229.3 (13 Oct 2015 22:46:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 13 Oct 2015 22:46:38 +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 Oct 14 00:46:38 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 1Zm8L8-0007uE-3i for geh-help-gnu-emacs@m.gmane.org; Wed, 14 Oct 2015 00:46:38 +0200 Original-Received: from localhost ([::1]:39679 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zm8L7-0006GK-7c for geh-help-gnu-emacs@m.gmane.org; Tue, 13 Oct 2015 18:46:37 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 36 Original-X-Trace: individual.net RdYovpvDgHvnKPwLQqYLbAiZEIuxmXFcGy01fiAoYk4gTef6cJ Cancel-Lock: sha1:aCK9026FJjr6+2BH1YhOU4Zo2ec= Mail-Copies-To: nobody X-Editor: Emacs of course! User-Agent: slrn/1.0.1 (Linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:215344 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:107628 Archived-At: Kaushal Modi wrote: > ​. Updated https://gist.github.com/kaushalmodi/ab487f63727381179f61​ You should byte-compile them. Makes the difference between cl-count and the rest even bigger. These are the results from only one run (each function called 100000 times), but I get similar results when I repeat the test: ,---- | cl-count 0.697451 | count-char-in-string-cl-count 0.743856 | count-char-in-string-mapcar 2.196961 | count-char-in-string-mapc 1.817378 | count-char-in-string-cdr 1.669147 | count-char-in-string-string-match 3.815134 `---- (I left out split-string as it produces the wrong result when the char being counted appears twice in a row.) The cl-count vs. count-char-in-string-cl-count are a direct call to cl-count vs. cl-count wrapped in a function. There is obviously some overhead to the additional function call, but even then cl-count wins hands down. Code is here: https://gist.github.com/joostkremers/0e07a35c85758a2fcb52 -- Joost Kremers joostkremers@fastmail.fm Selbst in die Unterwelt dringt durch Spalten Licht EN:SiS(9)