[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/elisp-benchmarks d7f3b38a26b 50/54: elisp-benchmarks.el: Compact
From: |
Pip Cet |
Subject: |
scratch/elisp-benchmarks d7f3b38a26b 50/54: elisp-benchmarks.el: Compact output and support setup code |
Date: |
Sat, 4 Jan 2025 12:26:38 -0500 (EST) |
branch: scratch/elisp-benchmarks
commit d7f3b38a26bb981eda47339d054e0d2bdca7e60d
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
elisp-benchmarks.el: Compact output and support setup code
* elisp-benchmarks.el (elisp-benchmarks--call-benchmark): New function.
(elisp-benchmarks-run): Use it. Make output format more compact.
Add new calling convention for benchmarks whose setup is costly
and should not be counted.
---
benchmarks/elisp-benchmarks.el | 66 +++++++++++++++++++++++++++++++-----------
1 file changed, 49 insertions(+), 17 deletions(-)
diff --git a/benchmarks/elisp-benchmarks.el b/benchmarks/elisp-benchmarks.el
index d254f1ae1de..85aad12c8ab 100644
--- a/benchmarks/elisp-benchmarks.el
+++ b/benchmarks/elisp-benchmarks.el
@@ -30,10 +30,24 @@
;; To add a new benchmark just depose the file into the benchmarks/
;; directory. Every benchmark foo.el has to define as entry-point a
-;; function foo-entry.
+;; function `elb-FOO-entry'.
+
+;; Entry points can choose one of two calling conventions:
+;;
+;; - Take no argument (and the result value is ignored).
+;; In this case the benchmark just measures the time it takes to run
+;; that function.
+;; - Take one argument MEASURING-FUNCTION: in that case, the
+;; entry point needs to call MEASURING-FUNCTION: once with
+;; a function (of no argument) as argument and it should return
+;; the value returned by MEASURING-FUNCTION.
+;; The benchmark measures the time it takes to run that function
+;; of no arguments.
+;; This calling convention is used when the benchmark needs to set things
+;; up before running the actual code that needs to be measured.
;; Tests are of an arbitrary length that on my machine is in the
-;; magnitude order of the 10 seconds for each single run
+;; order of magnitude of 10 seconds for each single run
;; byte-compiled. Please consider this as relative measure when
;; adding new benchmarks.
@@ -86,6 +100,11 @@
sum (expt (- x mean) 2))
(1- n)))))
+(defalias 'elisp-benchmarks--call-benchmark
+ (if (fboundp 'benchmark-call) ;Emacs-28
+ #'benchmark-call
+ (lambda (f) (benchmark-run nil (funcall f)))))
+
;;;###autoload
(cl-defun elisp-benchmarks-run (&optional selector (recompile t) runs)
"Run all the benchmarks and present the results.
@@ -141,23 +160,36 @@ RECOMPILE all the benchmark folder when non nil."
named test-loop
do
(message "Iteration number: %d" i)
- (cl-loop for test in tests
- for entry-point = (intern (concat "elb-" test "-entry"))
- do
- (garbage-collect)
- (message "Running %s..." test)
- (let ((time
- (with-demoted-errors "Error running: %S"
- (eval `(benchmark-run nil (,entry-point)) t))))
- (when time
- (push time (gethash test res)))))
+ (cl-loop
+ for test in tests
+ for entry-point = (intern (concat "elb-" test "-entry"))
+ do
+ (garbage-collect)
+ (message "Running %s..." test)
+ (let ((time
+ (with-demoted-errors "Error running: %S"
+ ;; There are two calling conventions for the
+ ;; benchmarks: either it's just a function
+ ;; of no argument (old, simple convention), or
+ ;; it's a function that takes our measuring function
+ ;; as argument (and should return its value).
+ ;; The more complex convention is used so the
+ ;; benchmark can set things up before running the
+ ;; code that we want to measure.
+ (condition-case nil
+ (funcall entry-point
+ #'elisp-benchmarks--call-benchmark)
+ (wrong-number-of-arguments
+ (elisp-benchmarks--call-benchmark entry-point))))))
+ (when time
+ (push time (gethash test res)))))
finally
(setq debug-on-error t)
(pop-to-buffer elb-result-buffer-name)
(erase-buffer)
(insert "* Results\n\n")
- (insert " |test|non-gc avg (s)|gc avg (s)|gcs avg|tot avg
(s)|tot avg err (s)\n")
+ (insert " |test|non-gc (s)|gc (s)|gcs|total (s)\n")
(insert "|-\n")
(cl-loop for test in tests
for l = (gethash test res)
@@ -166,23 +198,23 @@ RECOMPILE all the benchmark folder when non nil."
for test-gc-elapsed = (cl-loop for x in l sum (caddr x))
for test-err = (elb-std-deviation (mapcar #'car l))
do
- (insert (apply #'format "|%s|%.2f|%.2f|%d|%.2f" test
+ (insert (apply #'format "|%s|%.2f|%.2f|%d|%.2f (" test
(mapcar (lambda (x) (/ x runs))
(list (- test-elapsed
test-gc-elapsed)
test-gc-elapsed test-gcs
test-elapsed))))
- (insert (format "|%.2f\n" test-err))
+ (insert (format "±%.2f)\n" test-err))
summing test-elapsed into elapsed
summing test-gcs into gcs
summing test-gc-elapsed into gc-elapsed
collect test-err into errs
finally
(insert "|-\n")
- (insert (apply #'format "|total|%.2f|%.2f|%d|%.2f"
+ (insert (apply #'format "|total|%.2f|%.2f|%d|%.2f ("
(mapcar (lambda (x) (/ x runs))
(list (- elapsed gc-elapsed)
gc-elapsed gcs elapsed))))
- (insert (format "|%.2f\n"
+ (insert (format "±%.2f)\n"
(sqrt (apply #'+ (mapcar (lambda (x)
(expt x 2))
errs))))))
- scratch/elisp-benchmarks 8d15a1e6601 26/54: Make `comp-speed' controllable through a customize, (continued)
- scratch/elisp-benchmarks 8d15a1e6601 26/54: Make `comp-speed' controllable through a customize, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks a0d6af36237 28/54: * elisp-benchmarks.el: Bump new version., Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 0458ad6d03d 30/54: * elisp-benchmarks.el : Rename feature nativecomp -> feature-nativecompile, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks ba18acd0c17 32/54: ; * benchmarks/pack-unpack.el: Remove unnecessary newlines., Pip Cet, 2025/01/04
- scratch/elisp-benchmarks f43385543fc 46/54: * Handle 'compilation-safety', Pip Cet, 2025/01/04
- scratch/elisp-benchmarks f0132de78c1 47/54: * elisp-benchmarks.el: Bump new version., Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 3dba0bfbf4d 37/54: * benchmarks/elb-bytecomp.el: New benchmark, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 0dc090098dd 34/54: Add EIEIO benchmark, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 2eb211695bc 43/54: * benchmarks/elb-smie.el (elb-font-lock-entry): New benchmark, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 6965195a757 49/54: * elisp-benchmarks.el: Bump new version., Pip Cet, 2025/01/04
- scratch/elisp-benchmarks d7f3b38a26b 50/54: elisp-benchmarks.el: Compact output and support setup code,
Pip Cet <=
- scratch/elisp-benchmarks a32a99ae8af 54/54: New script to import an elpa module, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 59b2387ba71 52/54: Add "elisp-benchmarks" package from ELPA, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 908c78fe2bb 42/54: ; Prefer HTTPS to HTTP in URLs, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 9f4ff70129a 10/54: * elisp-benchmarks.el: Typo fix, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 30ca0c4dd09 21/54: * elisp-benchmarks.el (elisp-benchmarks-run): Use featurep to detect nativecomp, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 9df4eede3a4 25/54: Revert "Make `comp-speed' explicit in each benchmark", Pip Cet, 2025/01/04
- scratch/elisp-benchmarks d2c1c63f843 22/54: * Fix for new `native-compile' interface and bump new version, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 9f43793a688 31/54: * Rename comp-speed -> native-comp-speed + bump new version, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 563742243f5 41/54: * elisp-benchmarks.el: Bump version, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks d657ccc7fae 38/54: Make it usable on Emacs-27, Pip Cet, 2025/01/04