help-gnu-emacs
[Top][All Lists]
Advanced

[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: Joost Kremers
Subject: Re: How to count the number of occurrences of a character in a string?
Date: 13 Oct 2015 22:44:58 GMT
User-agent: slrn/1.0.1 (Linux)

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)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]