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

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

interactive feel of Emacs: the need for speed, and -Q [measure.el]


From: Emanuel Berg
Subject: interactive feel of Emacs: the need for speed, and -Q [measure.el]
Date: Mon, 30 Mar 2020 07:00:46 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Elisp: Last in this post, for the impatient.

Question: Second last in this post, for the ... whatever.

Some time ago, I assembled a supposedly gamer computer.
This sounds cool but actually it was easy, anyone can do
it, it is just a matter of money. (This should be
contrasted to all other paths of life, which are 100%
altruistic. Errr)

Anyway before that, I had an RPi, which I used as
a general-purpose computer. I got used to the low speed
and didn't feel that was a problem.

Now when I'm in game mode, I do experience a significant
decrease in compile time and such tasks, and a noticable
speedup WRT the interactive feel of Emacs.

I have an Elisp program [last] which I ran with the RPi,
and now on this computer. Three functions are executed
10 000 times each, and then the execution times
are outputted.

The unit is "a float number of seconds since the epoch",
as `float-time' is used.

On the RPi, times were 0.08, 0.38, and 0.55. On the gamer
computer, the same tests are done in times 0.01, 0.01,
and 0.05. (Maybe 0.01 indicates "too fast to measure"?)
So if I've done the math correctly, comparing the two
computers, the gamer computer has at least an 88%, 97%,
and 91% edge!

Still, when I invoke Emacs with -Q, the interactive feel
is much faster. This was true on the RPi as well, and the
relative difference was felt to be roughly the same.

The explanation given when this has been discussed is
that a lot of configuration/extension imposes hooks that
slow down the interactive feel. However I can't say
a rely a lot on hooks. When I do, they are one line of
Elisp to toggle `line-number-mode', and such. I _do_ have
a lot of Elisp (some 7 000 lines), *but* what I can see it
is for the most part just chunks of code that are not
used on an everyday basis. I have as much zsh shell
functions and they certainly do not slow zsh down by just
being there!

So I wonder, what exactly is brought in _without_ -Q that
slow Emacs down, and in particular the interactive feel?

Thanks for reading :)

;;; -*- lexical-binding: t -*-
;;;
;;; this file: http://user.it.uu.se/~embe8573/emacs-init/measure.el
;;;            https://dataswamp.org/~incal/emacs-init/measure.el

(require 'cl-lib)

(defun point-at-final-line-1 ()
  (= (line-number-at-pos)
     (line-number-at-pos (point-max)) ))

(defun point-at-final-line-2 ()
  (save-excursion
    (end-of-line)
    (= 1 (forward-line) )))

(defun point-at-final-line-3 ()
  (= (line-end-position) (point-max)) )

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

(defun create-random-list (max len)
  (let ((l '()))
    (cl-loop repeat len do
      (push (random max) l))
    l) )

(defun test-final-line-f (fun pos-list)
  (cl-loop for p in pos-list do
    (goto-char p)
    (apply fun nil) ))

(defun test-final-line (its)
  (let*((max      (point-max))
        (pos-list (create-random-list max its))
        (funs     (list #'point-at-final-line-1
                        #'point-at-final-line-2
                        #'point-at-final-line-3) )
        (times    '()) )
    (cl-loop for f in funs do
      (push (list f (measure-time (test-final-line-f f pos-list))) times) )
    (goto-char (point-max))
    (let ((sorted-times (cl-sort times #'< :key #'cadr)))
      (cl-loop for time in sorted-times do
        (insert (format "\n;; %s  %0.2f" (car time) (cadr time))) ))))

;; (test-final-line 10000)
;;                        ^eval me
;; results on RPi3:
;;
;;   point-at-final-line-3  0.08
;;   point-at-final-line-2  0.38
;;   point-at-final-line-1  0.55
;;
;; gamer computer:
;;
;;   point-at-final-line-3  0.01
;;   point-at-final-line-2  0.01
;;   point-at-final-line-1  0.05
;;
;; improvements:
;;
;;   (format "%.0f%%" (- 100 (* 100 (/ 0.01 0.08)))) ; 88%
;;   (format "%.0f%%" (- 100 (* 100 (/ 0.01 0.38)))) ; 97%
;;   (format "%.0f%%" (- 100 (* 100 (/ 0.05 0.55)))) ; 91%

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




reply via email to

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