diff options
| author | Lars Ingebrigtsen | 2019-10-15 08:19:08 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-10-15 08:19:14 +0200 |
| commit | ddc9837bf48c99c31df397438175afc2f9d3819c (patch) | |
| tree | ee6b48e346a3544e2cdd276a0e54f14285c6ad43 | |
| parent | 7acc621e373ba1371495e15e5e78aa6ce948a9a6 (diff) | |
| download | emacs-ddc9837bf48c99c31df397438175afc2f9d3819c.tar.gz emacs-ddc9837bf48c99c31df397438175afc2f9d3819c.zip | |
Add new macro `benchmark-progn'
* doc/lispref/debugging.texi (Profiling): Mention it.
* lisp/emacs-lisp/benchmark.el (benchmark-progn): New macro.
| -rw-r--r-- | doc/lispref/debugging.texi | 6 | ||||
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/emacs-lisp/benchmark.el | 24 |
3 files changed, 33 insertions, 3 deletions
diff --git a/doc/lispref/debugging.texi b/doc/lispref/debugging.texi index 71e767d0a66..b7eca1e50f8 100644 --- a/doc/lispref/debugging.texi +++ b/doc/lispref/debugging.texi | |||
| @@ -1041,9 +1041,9 @@ functions written in Lisp, it cannot profile Emacs primitives. | |||
| 1041 | @cindex benchmarking | 1041 | @cindex benchmarking |
| 1042 | You can measure the time it takes to evaluate individual Emacs Lisp | 1042 | You can measure the time it takes to evaluate individual Emacs Lisp |
| 1043 | forms using the @file{benchmark} library. See the macros | 1043 | forms using the @file{benchmark} library. See the macros |
| 1044 | @code{benchmark-run} and @code{benchmark-run-compiled} in | 1044 | @code{benchmark-run}, @code{benchmark-run-compiled} and |
| 1045 | @file{benchmark.el}. You can also use the @code{benchmark} command | 1045 | @code{benchmark-progn} in @file{benchmark.el}. You can also use the |
| 1046 | for timing forms interactively. | 1046 | @code{benchmark} command for timing forms interactively. |
| 1047 | 1047 | ||
| 1048 | @c Not worth putting in the printed manual. | 1048 | @c Not worth putting in the printed manual. |
| 1049 | @ifnottex | 1049 | @ifnottex |
| @@ -2399,6 +2399,12 @@ scrolling. | |||
| 2399 | 2399 | ||
| 2400 | * Lisp Changes in Emacs 27.1 | 2400 | * Lisp Changes in Emacs 27.1 |
| 2401 | 2401 | ||
| 2402 | +++ | ||
| 2403 | ** New macro 'benchmark-progn' | ||
| 2404 | This macro works like 'progn', but messages how long it takes to | ||
| 2405 | evaluate the body forms. The value of the last form is the return | ||
| 2406 | value. | ||
| 2407 | |||
| 2402 | ** New function 'read-char-with-history'. | 2408 | ** New function 'read-char-with-history'. |
| 2403 | This function works like 'read-char', but maintains a history that can | 2409 | This function works like 'read-char', but maintains a history that can |
| 2404 | be navigated via the 'M-p'/'M-n' keystrokes. | 2410 | be navigated via the 'M-p'/'M-n' keystrokes. |
diff --git a/lisp/emacs-lisp/benchmark.el b/lisp/emacs-lisp/benchmark.el index 8f12858b033..278fb807fd5 100644 --- a/lisp/emacs-lisp/benchmark.el +++ b/lisp/emacs-lisp/benchmark.el | |||
| @@ -107,6 +107,30 @@ For non-interactive use see also `benchmark-run' and | |||
| 107 | (message "Elapsed time: %fs (%fs in %d GCs)" (car result) | 107 | (message "Elapsed time: %fs (%fs in %d GCs)" (car result) |
| 108 | (nth 2 result) (nth 1 result))))) | 108 | (nth 2 result) (nth 1 result))))) |
| 109 | 109 | ||
| 110 | ;;;###autoload | ||
| 111 | (defmacro benchmark-progn (&rest body) | ||
| 112 | "Evaluate BODY and message the time taken. | ||
| 113 | The return value is the value of the final form in BODY." | ||
| 114 | (declare (debug body) (indent 0)) | ||
| 115 | (let ((value (make-symbol "value")) | ||
| 116 | (start (make-symbol "start")) | ||
| 117 | (gcs (make-symbol "gcs")) | ||
| 118 | (gc (make-symbol "gc"))) | ||
| 119 | `(let ((,gc gc-elapsed) | ||
| 120 | (,gcs gcs-done) | ||
| 121 | (,start (current-time)) | ||
| 122 | (,value (progn | ||
| 123 | ,@body))) | ||
| 124 | (message "Elapsed time: %fs%s" | ||
| 125 | (float-time (time-since ,start)) | ||
| 126 | (if (> (- gcs-done ,gcs) 0) | ||
| 127 | (format " (%fs in %d GCs)" | ||
| 128 | (- gc-elapsed ,gc) | ||
| 129 | (- gcs-done ,gcs)) | ||
| 130 | "")) | ||
| 131 | ;; Return the value of the body. | ||
| 132 | ,value))) | ||
| 133 | |||
| 110 | (provide 'benchmark) | 134 | (provide 'benchmark) |
| 111 | 135 | ||
| 112 | ;;; benchmark.el ends here | 136 | ;;; benchmark.el ends here |