]> git.eshelyaron.com Git - emacs.git/commitdiff
(benchmark-run-compiled): Make it work like 'benchmark-run' again
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 27 Mar 2018 20:19:40 +0000 (16:19 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 27 Mar 2018 20:19:40 +0000 (16:19 -0400)
* lisp/emacs-lisp/benchmark.el (benchmark-run): Add special case for
nil repetitions.

etc/NEWS
lisp/emacs-lisp/benchmark.el
test/lisp/emacs-lisp/benchmark-tests.el

index 04774c13e55a78cfc62b723665d7bc4e676032a4..fd1d04b8a041f6bbc77a389f764c28690bc7230f 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -326,6 +326,7 @@ names" in the Tramp manual for full documentation of these facilities.
 \f
 * Incompatible Lisp Changes in Emacs 27.1
 
+** The 'repetitions' argument of 'benchmark-run' can now also be a variable.
 ** The FILENAME argument to 'file-name-base' is now mandatory and no
 longer defaults to 'buffer-file-name'.
 
index 2f4e38fe3566c4922060e1bcef31c47e53d07184..e062a1867a8835fd225ea1081d6015cebfbc06af 100644 (file)
@@ -50,7 +50,7 @@ Return a list of the total elapsed time for execution, the number of
 garbage collections that ran, and the time taken by garbage collection.
 See also `benchmark-run-compiled'."
   (declare (indent 1) (debug t))
-  (unless (or (natnump repetitions) (symbolp repetitions))
+  (unless (or (natnump repetitions) (and repetitions (symbolp repetitions)))
     (setq forms (cons repetitions forms)
          repetitions 1))
   (let ((i (make-symbol "i"))
@@ -74,7 +74,7 @@ This is like `benchmark-run', but what is timed is a funcall of the
 byte code obtained by wrapping FORMS in a `lambda' and compiling the
 result.  The overhead of the `lambda's is accounted for."
   (declare (indent 1) (debug t))
-  (unless (natnump repetitions)
+  (unless (or (natnump repetitions) (and repetitions (symbolp repetitions)))
     (setq forms (cons repetitions forms)
          repetitions 1))
   (let ((i (make-symbol "i"))
@@ -84,7 +84,7 @@ result.  The overhead of the `lambda's is accounted for."
        (lambda-code (byte-compile `(lambda ()))))
     `(let ((,gc gc-elapsed)
           (,gcs gcs-done))
-       (list ,(if (> repetitions 1)
+       (list ,(if (or (symbolp repetitions) (> repetitions 1))
                  ;; Take account of the loop overhead.
                  `(- (benchmark-elapse (dotimes (,i ,repetitions)
                                          (funcall ,code)))
index cba53aefc9f65a67451735e2fe02d2e60f5e750e..26bd3ff08a8849f9bdc3f326949b4faec08475c7 100644 (file)
     (should (consp (benchmark-run 1 (setq m (1+ 0)))))
     (should (stringp (benchmark nil (1+ 0))))
     (should (stringp (benchmark 1 (1+ 0))))
-    (should (consp (benchmark-run-compiled nil (1+ 0))))
+    (should (consp (benchmark-run-compiled (1+ 0))))
     (should (consp (benchmark-run-compiled 1 (1+ 0))))
     ;; First test is heavier, must need longer time.
-    (should (> (car (benchmark-run nil
+    (let ((count1 0)
+          (count2 0)
+          (repeat 2))
+      (ignore (benchmark-run (setq count1 (1+ count1))))
+      (ignore (benchmark-run repeat (setq count2 (1+ count2))))
+      (should (> count2 count1)))
+    (should (> (car (benchmark-run
                       (let ((n 100000)) (while (> n 1) (setq n (1- n))))))
-               (car (benchmark-run nil (setq m (1+ 0))))))
-    (should (> (car (benchmark-run nil
+               (car (benchmark-run (setq m (1+ 0))))))
+    (should (> (car (benchmark-run
                       (let ((n 100000)) (while (> n 1) (setq n (1- n))))))
-               (car (benchmark-run nil (setq m (1+ 0))))))
-    (should (> (car (benchmark-run-compiled nil
+               (car (benchmark-run (setq m (1+ 0))))))
+    (should (> (car (benchmark-run-compiled
                       (let ((n 100000)) (while (> n 1) (setq n (1- n))))))
-               (car (benchmark-run-compiled nil (1+ 0)))))
+               (car (benchmark-run-compiled (1+ 0)))))
     (setq str (benchmark nil '(let ((n 100000)) (while (> n 1) (setq n (1- n))))))
     (string-match "Elapsed time: \\([0-9.]+\\)" str)
     (setq t-long (string-to-number (match-string 1 str)))