el-get/test/caching-speedtest.el
Stephan Creutz ccca97f226 Replace cl by cl-lib
Since Emacs 27 the package cl is deprecated, the replacement is
cl-lib, which is available since Emacs 24.3.

This patch replaces cl by cl-lib and drops support for Emacs versions
less than 24.3. Dropping older Emacsen is required, because cl-lib is
a builtin starting from version 24.3 and doesn't need an extra package
from ELPA.

Testcases for past issues still contain cl. Most of them seem to be
broken and need further investigation.

This patch is tested with test/run-ert.sh, which outputs:

Ran 10 tests, 10 results as expected, 0 unexpected (2021-01-30 13:24:54+0100, 0.672122 sec)
1 expected failures

and manually by daily usage for a month now.
2021-06-13 16:03:08 +02:00

55 lines
1.7 KiB
EmacsLisp

;; Benchmark for caching the package status alist
(require 'cl-lib)
(defmacro timeit (&rest body)
"Run body and report real time taken to do so."
`(let ((start-time (float-time)))
(progn ,@body)
(let ((end-time (float-time)))
(message "Completed in %.4f seconds" (- end-time start-time))
(- end-time start-time))))
(put 'timeit 'lisp-indent-function
(get 'progn 'lisp-indent-function))
(defmacro suppress-messages (&rest body)
"Run body with `message' redefined as a no-op."
`(cl-flet ((message (&rest ignored) nil))
(progn ,@body)))
(put 'suppress-messages 'lisp-indent-function
(get 'progn 'lisp-indent-function))
(setq debug-on-error t
el-get-verbose t
el-get-default-process-sync t
el-get-notify-type 'message
el-get-use-autoloads nil
el-get-byte-compile nil
repetitions 50
el-get-sources
(list
`(:name pkg :type builtin)))
;; Install and remove once to warm up the disk cache and whatever
(suppress-messages
(el-get-install 'pkg)
(el-get-remove 'pkg))
(message "Beginning benchmark")
;; Repeat benchmark 5 times to see consistency
(let ((times
(cl-loop
for rep from 1 upto 5
collect
(timeit
(suppress-messages
;; Benchmark is to repeatedly install, hit the cache 5 times,
;; and then remove the same package. Repeat N times.
(dotimes (x repetitions)
(el-get-install 'pkg)
(dotimes (y 5)
(el-get-read-package-status-recipe 'pkg)
(el-get-init 'pkg))
(el-get-remove 'pkg)))))))
(message "Summary: %S" (mapcar (lambda (n) (string-to-number (format "%.4f" n))) times)))
(message "Finished benchmark")