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: Kaushal Modi
Subject: Re: How to count the number of occurrences of a character in a string?
Date: Tue, 13 Oct 2015 16:41:13 -0400

Just tried that, mapc is the best alternative after cl-count.

Updated the results and code at
https://gist.github.com/kaushalmodi/ab487f63727381179f61

--
Kaushal Modi


On Tue, Oct 13, 2015 at 4:17 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Kaushal Modi <kaushal.modi@gmail.com>
>> Date: Tue, 13 Oct 2015 15:56:57 -0400
>> Cc: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
>>
>> 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
>
> Looks like 1000 loops is too few: your measurements hit clock
> quantization error, and also some background activities affect the
> results.  I suggest to try 10000 iterations.
>
> Also, did you actually try 'mapc', per my second suggestion?
>



reply via email to

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