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 15:56:57 -0400

Thanks!

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
1000 executions of string-match-p approach took 0.047496 seconds
1000 executions of cl-count approach took 0.035816 seconds
1000 executions of cdr approach took 0.043535 seconds
nil
1000 executions of string-match-p approach took 0.047068 seconds
1000 executions of cl-count approach took 0.035923 seconds
1000 executions of cdr approach took 0.043363 seconds
nil
1000 executions of string-match-p approach took 0.047406 seconds
1000 executions of cl-count approach took 0.034490 seconds
1000 executions of cdr approach took 0.043718 seconds
nil
1000 executions of string-match-p approach took 0.047117 seconds
1000 executions of cl-count approach took 0.035804 seconds
1000 executions of cdr approach took 0.043340 seconds
nil
1000 executions of string-match-p approach took 0.208332 seconds
1000 executions of cl-count approach took 0.035798 seconds
1000 executions of cdr approach took 0.043902 seconds
nil
1000 executions of string-match-p approach took 0.047357 seconds
1000 executions of cl-count approach took 0.035955 seconds
1000 executions of cdr approach took 0.043331 seconds
nil


--
Kaushal Modi


On Tue, Oct 13, 2015 at 3:07 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Kaushal Modi <kaushal.modi@gmail.com>
>> Date: Tue, 13 Oct 2015 13:43:05 -0400
>> Cc: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
>>
>> I am, though, unable to quantify which approach is the fastest using
>> `benchmark`.
>>
>> I ran the below wrapper progn block couple of times and I got
>> different results each time. Oddly enough, I even got negative
>> execution times.
>> What am I doing wrong?
>
> Could be a bug in 'benchmark'.  Just call float-time before and after,
> and subtract the values, it should be good enough.
>



reply via email to

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