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))
,@forms
(float-time (time-since ,t1)))))
(defun mode-line-benchmark ()
(interactive)
(let* ((value nil)
(repetitions 10000)
(wall-clock-time
(mode-line-benchmark-elapse-time
(dotimes (_ repetitions)
(setq value (format-mode-line mode-line-format)))))
(average-time (/ wall-clock-time repetitions)))
(message
"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
:eval
to run code, which could become slow. – ideasman42 Jun 23 '20 at 4:00:eval
can take a hit when redisplay happens. You might be able to otherwise check performance hits that you impose by usingforce-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:31measure-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