diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2019-10-15 08:19:08 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2019-10-15 08:19:14 +0200 |
commit | ddc9837bf48c99c31df397438175afc2f9d3819c (patch) | |
tree | ee6b48e346a3544e2cdd276a0e54f14285c6ad43 /lisp/emacs-lisp | |
parent | 7acc621e373ba1371495e15e5e78aa6ce948a9a6 (diff) | |
download | emacs-ddc9837bf48c99c31df397438175afc2f9d3819c.tar.gz emacs-ddc9837bf48c99c31df397438175afc2f9d3819c.tar.bz2 emacs-ddc9837bf48c99c31df397438175afc2f9d3819c.zip |
Add new macro `benchmark-progn'
* doc/lispref/debugging.texi (Profiling): Mention it.
* lisp/emacs-lisp/benchmark.el (benchmark-progn): New macro.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/benchmark.el | 24 |
1 files changed, 24 insertions, 0 deletions
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 (message "Elapsed time: %fs (%fs in %d GCs)" (car result) (nth 2 result) (nth 1 result))))) +;;;###autoload +(defmacro benchmark-progn (&rest body) + "Evaluate BODY and message the time taken. +The return value is the value of the final form in BODY." + (declare (debug body) (indent 0)) + (let ((value (make-symbol "value")) + (start (make-symbol "start")) + (gcs (make-symbol "gcs")) + (gc (make-symbol "gc"))) + `(let ((,gc gc-elapsed) + (,gcs gcs-done) + (,start (current-time)) + (,value (progn + ,@body))) + (message "Elapsed time: %fs%s" + (float-time (time-since ,start)) + (if (> (- gcs-done ,gcs) 0) + (format " (%fs in %d GCs)" + (- gc-elapsed ,gc) + (- gcs-done ,gcs)) + "")) + ;; Return the value of the body. + ,value))) + (provide 'benchmark) ;;; benchmark.el ends here |