[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to count the number of occurrences of a character in a string?
From: |
Kaushal Modi |
Subject: |
Re: How to count the number of occurrences of a character in a string? |
Date: |
Tue, 13 Oct 2015 17:07:32 -0400 |
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
>
- Re: How to count the number of occurrences of a character in a string?, (continued)
- Re: How to count the number of occurrences of a character in a string?, Kaushal Modi, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?, Kaushal Modi, 2015/10/15
- Re: How to count the number of occurrences of a character in a string?, Eli Zaretskii, 2015/10/15
- Re: How to count the number of occurrences of a character in a string?, Eli Zaretskii, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?, Kaushal Modi, 2015/10/15
- Re: How to count the number of occurrences of a character in a string?, Eli Zaretskii, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?, Kaushal Modi, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?, Eli Zaretskii, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?, Kaushal Modi, 2015/10/13
- Message not available
- Re: How to count the number of occurrences of a character in a string?, Brendan Halpin, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?,
Kaushal Modi <=
- Message not available
- Re: How to count the number of occurrences of a character in a string?, Joost Kremers, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?, Oleh Krehel, 2015/10/14
- Re: How to count the number of occurrences of a character in a string?, Eli Zaretskii, 2015/10/14
- Re: How to count the number of occurrences of a character in a string?, Michael Heerdegen, 2015/10/13
- Re: How to count the number of occurrences of a character in a string?, Charles Curley, 2015/10/15
- Re: How to count the number of occurrences of a character in a string?, Noam Postavsky, 2015/10/15
- Re: How to count the number of occurrences of a character in a string?, Kaushal Modi, 2015/10/14
Re: How to count the number of occurrences of a character in a string?, Emanuel Berg, 2015/10/13
Re: How to count the number of occurrences of a character in a string?, Joost Kremers, 2015/10/12