emacs-devel
[Top][All Lists]
Advanced

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

Re: `add-face'


From: Lars Ingebrigtsen
Subject: Re: `add-face'
Date: Fri, 07 Sep 2012 16:13:10 +0200
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.2.50 (gnu/linux)

I've now done some simple benchmarking with the native function and the
next-property-change version, included below.

Setting a thousand face properties on a biggish web page isn't unusual.

With a hundred repetitions, the native version takes 12 seconds.  The
non-native one takes 91 seconds.  So on a realistic shr.el rendering,
fontifying with the native version takes 0.12 seconds, while the
non-native ones takes 0.91 seconds, so this seems worthwhile to me.
Especially with such a small change to the C code.

Shall I just check the code in, and then we can fiddle with it further?

(defun add-props-native ()
  (with-temp-buffer
    (dotimes (i 1000)
      (insert "this is a line of text and stuff\n"))
    (dotimes (i 1000)
      (let* ((start (1+ (random (1- (buffer-size)))))
             (length (random (- (buffer-size) start))))
        (add-face-text-property start (+ start length)
                                (if (zerop (mod length 2))
                                    'bold 'italic))))))

(defun add-props-non-native ()
  (with-temp-buffer
    (dotimes (i 1000)
      (insert "this is a line of text and stuff\n"))
    (dotimes (i 1000)
      (let* ((start (1+ (random (1- (buffer-size)))))
             (length (random (- (buffer-size) start))))
        (add-face start (+ start length)
                  (if (zerop (mod length 2))
                      'bold 'italic))))))


-- 
(domestic pets only, the antidote for overdose, milk.)
  http://lars.ingebrigtsen.no  *  Lars Magne Ingebrigtsen




reply via email to

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