(benchmark-run-compiled): Make it work like 'benchmark-run' again
* lisp/emacs-lisp/benchmark.el (benchmark-run): Add special case for nil repetitions.
This commit is contained in:
parent
b56c56f203
commit
7bc31c1cd4
3 changed files with 17 additions and 10 deletions
1
etc/NEWS
1
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'.
|
||||
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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)))
|
||||
|
|
Loading…
Add table
Reference in a new issue