From: Stefan Monnier Date: Tue, 27 Mar 2018 20:19:40 +0000 (-0400) Subject: (benchmark-run-compiled): Make it work like 'benchmark-run' again X-Git-Tag: emacs-27.0.90~5384 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7bc31c1cd4b6a6eac0d29e31dbe3d208e2258ccf;p=emacs.git (benchmark-run-compiled): Make it work like 'benchmark-run' again * lisp/emacs-lisp/benchmark.el (benchmark-run): Add special case for nil repetitions. --- 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. * 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'. 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 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))) 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 @@ (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)))