caching-speedtest.el 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
;; Benchmark for caching the package status alist

(require 'cl)

(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."
  `(flet ((message (&rest ignored) nil))
18
     (progn ,@body)))
19 20 21
(put 'suppress-messages 'lisp-indent-function
     (get 'progn 'lisp-indent-function))

22 23 24 25
(setq debug-on-error t
      el-get-verbose t
      el-get-default-process-sync t
      el-get-notify-type 'message
26
      el-get-use-autoloads nil
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
      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
       (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")