[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: looking-at-p slower than looking-at
From: |
Marcin Borkowski |
Subject: |
Re: looking-at-p slower than looking-at |
Date: |
Wed, 25 Nov 2015 21:34:46 +0100 |
User-agent: |
mu4e 0.9.13; emacs 25.0.50.1 |
On 2015-11-25, at 14:58, Nicolas Richard <nrichard@ulb.ac.be> wrote:
> Marcin Borkowski <mbork@mbork.pl> writes:
>
>> You might also (depending on your use-case) want to use looking-at-p,
>> which is marginally slower than looking-at, but does not modify match
>> data.
>
> Why is it slower and how much slower is it ? I don't see how it can
> happen from its implementation:
>
> (defsubst looking-at-p (regexp)
> "\
> Same as `looking-at' except this function does not change the match data."
> (let ((inhibit-changing-match-data t))
> (looking-at regexp)))
One more function call and one more variable binding. IMHO it /must/ be
slower, though I think the effect is negligible.
OTOH, this trivial and unscientific test:
(setq foo "foo")
(benchmark 10000000 (looking-at foo))
(benchmark 10000000 (looking-at-p foo))
was not conclusive. (AFAIU, it is of utmost importance that you don't
use literal strings in such a test, since then it is much more probable
that GC will kick in. Am I right?)
> thanks,
Best,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
Re: How to test if the current line contains only white-spache?, Rolf Ade, 2015/11/16