[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 7bc31c1: (benchmark-run-compiled): Make it work lik
From: |
Stefan Monnier |
Subject: |
[Emacs-diffs] master 7bc31c1: (benchmark-run-compiled): Make it work like 'benchmark-run' again |
Date: |
Tue, 27 Mar 2018 16:19:45 -0400 (EDT) |
branch: master
commit 7bc31c1cd4b6a6eac0d29e31dbe3d208e2258ccf
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>
(benchmark-run-compiled): Make it work like 'benchmark-run' again
* lisp/emacs-lisp/benchmark.el (benchmark-run): Add special case for
nil repetitions.
---
etc/NEWS | 1 +
lisp/emacs-lisp/benchmark.el | 6 +++---
test/lisp/emacs-lisp/benchmark-tests.el | 20 +++++++++++++-------
3 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 04774c1..fd1d04b 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 2f4e38f..e062a18 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 cba53ae..26bd3ff 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)))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 7bc31c1: (benchmark-run-compiled): Make it work like 'benchmark-run' again,
Stefan Monnier <=