aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2018-03-27 16:19:40 -0400
committerStefan Monnier2018-03-27 16:19:40 -0400
commit7bc31c1cd4b6a6eac0d29e31dbe3d208e2258ccf (patch)
treef518430c9d0998b05636965564750c5a30bbb659
parentb56c56f203f8b066dd71e6ae6a254121b3ac3f08 (diff)
downloademacs-7bc31c1cd4b6a6eac0d29e31dbe3d208e2258ccf.tar.gz
emacs-7bc31c1cd4b6a6eac0d29e31dbe3d208e2258ccf.zip
(benchmark-run-compiled): Make it work like 'benchmark-run' again
* lisp/emacs-lisp/benchmark.el (benchmark-run): Add special case for nil repetitions.
-rw-r--r--etc/NEWS1
-rw-r--r--lisp/emacs-lisp/benchmark.el6
-rw-r--r--test/lisp/emacs-lisp/benchmark-tests.el20
3 files changed, 17 insertions, 10 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 04774c13e55..fd1d04b8a04 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -326,6 +326,7 @@ names" in the Tramp manual for full documentation of these facilities.
326 326
327* Incompatible Lisp Changes in Emacs 27.1 327* Incompatible Lisp Changes in Emacs 27.1
328 328
329** The 'repetitions' argument of 'benchmark-run' can now also be a variable.
329** The FILENAME argument to 'file-name-base' is now mandatory and no 330** The FILENAME argument to 'file-name-base' is now mandatory and no
330longer defaults to 'buffer-file-name'. 331longer defaults to 'buffer-file-name'.
331 332
diff --git a/lisp/emacs-lisp/benchmark.el b/lisp/emacs-lisp/benchmark.el
index 2f4e38fe356..e062a1867a8 100644
--- a/lisp/emacs-lisp/benchmark.el
+++ b/lisp/emacs-lisp/benchmark.el
@@ -50,7 +50,7 @@ Return a list of the total elapsed time for execution, the number of
50garbage collections that ran, and the time taken by garbage collection. 50garbage collections that ran, and the time taken by garbage collection.
51See also `benchmark-run-compiled'." 51See also `benchmark-run-compiled'."
52 (declare (indent 1) (debug t)) 52 (declare (indent 1) (debug t))
53 (unless (or (natnump repetitions) (symbolp repetitions)) 53 (unless (or (natnump repetitions) (and repetitions (symbolp repetitions)))
54 (setq forms (cons repetitions forms) 54 (setq forms (cons repetitions forms)
55 repetitions 1)) 55 repetitions 1))
56 (let ((i (make-symbol "i")) 56 (let ((i (make-symbol "i"))
@@ -74,7 +74,7 @@ This is like `benchmark-run', but what is timed is a funcall of the
74byte code obtained by wrapping FORMS in a `lambda' and compiling the 74byte code obtained by wrapping FORMS in a `lambda' and compiling the
75result. The overhead of the `lambda's is accounted for." 75result. The overhead of the `lambda's is accounted for."
76 (declare (indent 1) (debug t)) 76 (declare (indent 1) (debug t))
77 (unless (natnump repetitions) 77 (unless (or (natnump repetitions) (and repetitions (symbolp repetitions)))
78 (setq forms (cons repetitions forms) 78 (setq forms (cons repetitions forms)
79 repetitions 1)) 79 repetitions 1))
80 (let ((i (make-symbol "i")) 80 (let ((i (make-symbol "i"))
@@ -84,7 +84,7 @@ result. The overhead of the `lambda's is accounted for."
84 (lambda-code (byte-compile `(lambda ())))) 84 (lambda-code (byte-compile `(lambda ()))))
85 `(let ((,gc gc-elapsed) 85 `(let ((,gc gc-elapsed)
86 (,gcs gcs-done)) 86 (,gcs gcs-done))
87 (list ,(if (> repetitions 1) 87 (list ,(if (or (symbolp repetitions) (> repetitions 1))
88 ;; Take account of the loop overhead. 88 ;; Take account of the loop overhead.
89 `(- (benchmark-elapse (dotimes (,i ,repetitions) 89 `(- (benchmark-elapse (dotimes (,i ,repetitions)
90 (funcall ,code))) 90 (funcall ,code)))
diff --git a/test/lisp/emacs-lisp/benchmark-tests.el b/test/lisp/emacs-lisp/benchmark-tests.el
index cba53aefc9f..26bd3ff08a8 100644
--- a/test/lisp/emacs-lisp/benchmark-tests.el
+++ b/test/lisp/emacs-lisp/benchmark-tests.el
@@ -28,18 +28,24 @@
28 (should (consp (benchmark-run 1 (setq m (1+ 0))))) 28 (should (consp (benchmark-run 1 (setq m (1+ 0)))))
29 (should (stringp (benchmark nil (1+ 0)))) 29 (should (stringp (benchmark nil (1+ 0))))
30 (should (stringp (benchmark 1 (1+ 0)))) 30 (should (stringp (benchmark 1 (1+ 0))))
31 (should (consp (benchmark-run-compiled nil (1+ 0)))) 31 (should (consp (benchmark-run-compiled (1+ 0))))
32 (should (consp (benchmark-run-compiled 1 (1+ 0)))) 32 (should (consp (benchmark-run-compiled 1 (1+ 0))))
33 ;; First test is heavier, must need longer time. 33 ;; First test is heavier, must need longer time.
34 (should (> (car (benchmark-run nil 34 (let ((count1 0)
35 (count2 0)
36 (repeat 2))
37 (ignore (benchmark-run (setq count1 (1+ count1))))
38 (ignore (benchmark-run repeat (setq count2 (1+ count2))))
39 (should (> count2 count1)))
40 (should (> (car (benchmark-run
35 (let ((n 100000)) (while (> n 1) (setq n (1- n)))))) 41 (let ((n 100000)) (while (> n 1) (setq n (1- n))))))
36 (car (benchmark-run nil (setq m (1+ 0)))))) 42 (car (benchmark-run (setq m (1+ 0))))))
37 (should (> (car (benchmark-run nil 43 (should (> (car (benchmark-run
38 (let ((n 100000)) (while (> n 1) (setq n (1- n)))))) 44 (let ((n 100000)) (while (> n 1) (setq n (1- n))))))
39 (car (benchmark-run nil (setq m (1+ 0)))))) 45 (car (benchmark-run (setq m (1+ 0))))))
40 (should (> (car (benchmark-run-compiled nil 46 (should (> (car (benchmark-run-compiled
41 (let ((n 100000)) (while (> n 1) (setq n (1- n)))))) 47 (let ((n 100000)) (while (> n 1) (setq n (1- n))))))
42 (car (benchmark-run-compiled nil (1+ 0))))) 48 (car (benchmark-run-compiled (1+ 0)))))
43 (setq str (benchmark nil '(let ((n 100000)) (while (> n 1) (setq n (1- n)))))) 49 (setq str (benchmark nil '(let ((n 100000)) (while (> n 1) (setq n (1- n))))))
44 (string-match "Elapsed time: \\([0-9.]+\\)" str) 50 (string-match "Elapsed time: \\([0-9.]+\\)" str)
45 (setq t-long (string-to-number (match-string 1 str))) 51 (setq t-long (string-to-number (match-string 1 str)))