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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: looking-at-p slower than looking-at


From: Emanuel Berg
Subject: Re: looking-at-p slower than looking-at
Date: Wed, 25 Nov 2015 23:39:00 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Nicolas Richard <nrichard@ulb.ac.be> writes:

> Why is it slower and how much slower is it ? I don't
> see how it can happen from its implementation

Why wouldn't it be slower? It does more things!

Here is a cool macro that confirms (by testing) that
it is indeed slower:

(defmacro measure-time (&rest body)
  "Measure and return the running time of the code block.
Not mine: http://nullprogram.com/blog/2009/05/28/";
  (declare (indent defun))
  (let ((start (make-symbol "start")))
    `(let ((,start (float-time)))
       ,@body
       (- (float-time) ,start))))

(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)))

(insert (format " ; %s" (measure-time (looking-at-p "a")))) ; 
1.5974044799804688e-05
(insert (format " ; %s" (measure-time (looking-at   "a")))) ; 
1.2874603271484375e-05

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

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