Currently when making changes to the mode-line, I try to write efficient elisp,

However I don't know for sure if what I'm doing is in fact efficient.

How could I test the mode-line performance?

For example - redraw the mode-line in a loop and time that.

  • what are you displaying on your mode line?
    – Tyler
    Jun 23 '20 at 3:18
  • Just ascii text - nothing special, it's just that I'm using :eval to run code, which could become slow.
    – ideasman42
    Jun 23 '20 at 4:00
  • Redisplay affects mode-line behavior and apparent performance. And :eval can take a hit when redisplay happens. You might be able to otherwise check performance hits that you impose by using force-mode-line-update, but my guess is that all bets are off, in this regard - because you don't control when or how often redisplay occurs. But perhaps someone more knowledgeable will have something better to offer.
    – Drew
    Jun 23 '20 at 4:31
  • Here is a link to a S.O. thread that uses a measure-time macro from the Emacs help mailing list: stackoverflow.com/questions/23622296/… The link to the Emacs help mail list thread is: lists.gnu.org/archive/html/help-gnu-emacs/2008-06/msg00087.html
    – lawlist
    Jun 23 '20 at 6:02

This interactive function times format-mode-line.

(defmacro mode-line-benchmark-elapse-time (&rest forms)
  "Return the time in seconds elapsed for execution of FORMS."
  (declare (indent 0) (debug t))
  (let ((t1 (make-symbol "t1")))
    (let (,t1)
      (setq ,t1 (current-time))
      (float-time (time-since ,t1)))))

(defun mode-line-benchmark ()
  (let* ((value nil)
         (repetitions 10000)
            (dotimes (_ repetitions)
              (setq value (format-mode-line mode-line-format)))))
         (average-time (/ wall-clock-time repetitions)))
     "Time: %.10f per call, %.10f for %S calls: %S"
     average-time wall-clock-time repetitions value)))

This can be run manually with M-x mode-line-benchmark

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.