From: Kaushal Modi <kaushal.modi@gmail.com>
To: brendan.halpin@ul.ie
Cc: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: How to count the number of occurrences of a character in a string?
Date: Tue, 13 Oct 2015 17:07:32 -0400 [thread overview]
Message-ID: <CAFyQvY3SHAo9kAD955GOEfAjxbx5M3DZ64Qw6gLycpqOZhb1DQ@mail.gmail.com> (raw)
In-Reply-To: <87wpuqxzrx.fsf@ul.ie>
Looks like mapcar is
now at
the 2nd place by a hair.. mapc drops down to 3rd place
. Updated https://gist.github.com/kaushalmodi/ab487f63727381179f61
;; Fastest to slowest approach;;;;
|------+--------------+-----------------------|;; | Rank | Method | Time in
second |;; | | | for 100000 executions |;; | | | (very rough avg) |;;
|------+--------------+-----------------------|;; | 1 | cl-count | 1.0 to
1.6 |;; | 2 | mapcar | 1.9 to 2.1 |;; | 3 | mapc | 2.0 to 2.6 |;; | 4 | cdr
| 2.4 to 3.3 |;; | 5 | split-string | 4.0 to 4.7 |;; | 5* | string-match |
3.7 to 4.7 |;; |------+--------------+-----------------------|
--
Kaushal Modi
On Tue, Oct 13, 2015 at 4:46 PM, Brendan Halpin <brendan.halpin@ul.ie>
wrote:
> On Tue, Oct 13 2015, Eli Zaretskii wrote:
>
> > Also, did you actually try 'mapc', per my second suggestion?
>
> Why not mapcar?
>
> (defun test (str char)
> (apply '+ (mapcar (lambda (x) (if (= x char) 1 0))
> str)))
>
> B
> --
> Brendan Halpin, Head, Department of Sociology, University of Limerick,
> Ireland
> Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room F1-002 x
> 3147
> mailto:brendan.halpin@ul.ie ULSociology on Facebook:
> http://on.fb.me/fjIK9t
> http://teaching.sociology.ul.ie/bhalpin/wordpress
> twitter:@ULSociology
>
next prev parent reply other threads:[~2015-10-13 21:07 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-12 19:45 How to count the number of occurrences of a character in a string? Marcin Borkowski
2015-10-12 21:43 ` Kaushal Modi
2015-10-12 23:27 ` Nick Dokos
2015-10-13 1:18 ` Stefan Monnier
2015-10-13 16:06 ` Kaushal Modi
2015-10-13 16:31 ` Kaushal Modi
2015-10-13 16:48 ` Eli Zaretskii
2015-10-13 17:41 ` Eli Zaretskii
2015-10-13 17:43 ` Kaushal Modi
2015-10-13 19:07 ` Eli Zaretskii
2015-10-13 19:56 ` Kaushal Modi
2015-10-13 20:17 ` Eli Zaretskii
2015-10-13 20:41 ` Kaushal Modi
[not found] ` <mailman.267.1444767491.7904.help-gnu-emacs@gnu.org>
2015-10-13 20:46 ` Brendan Halpin
2015-10-13 21:07 ` Kaushal Modi [this message]
[not found] ` <mailman.273.1444770543.7904.help-gnu-emacs@gnu.org>
2015-10-13 22:44 ` Joost Kremers
2015-10-14 10:04 ` Oleh Krehel
2015-10-14 17:06 ` Eli Zaretskii
2015-10-13 20:43 ` Michael Heerdegen
2015-10-13 20:59 ` Charles Curley
2015-10-14 18:19 ` Noam Postavsky
2015-10-14 20:00 ` Kaushal Modi
2015-10-13 22:00 ` Emanuel Berg
[not found] <mailman.164.1444679125.7904.help-gnu-emacs@gnu.org>
2015-10-12 23:35 ` Joost Kremers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFyQvY3SHAo9kAD955GOEfAjxbx5M3DZ64Qw6gLycpqOZhb1DQ@mail.gmail.com \
--to=kaushal.modi@gmail.com \
--cc=brendan.halpin@ul.ie \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.