emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master ddc9837: Add new macro `benchmark-progn'


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master ddc9837: Add new macro `benchmark-progn'
Date: Tue, 15 Oct 2019 02:19:20 -0400 (EDT)

branch: master
commit ddc9837bf48c99c31df397438175afc2f9d3819c
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Add new macro `benchmark-progn'
    
    * doc/lispref/debugging.texi (Profiling): Mention it.
    
    * lisp/emacs-lisp/benchmark.el (benchmark-progn): New macro.
---
 doc/lispref/debugging.texi   |  6 +++---
 etc/NEWS                     |  6 ++++++
 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 71e767d..b7eca1e 100644
--- a/doc/lispref/debugging.texi
+++ b/doc/lispref/debugging.texi
@@ -1041,9 +1041,9 @@ functions written in Lisp, it cannot profile Emacs 
primitives.
 @cindex benchmarking
 You can measure the time it takes to evaluate individual Emacs Lisp
 forms using the @file{benchmark} library.  See the macros
-@code{benchmark-run} and @code{benchmark-run-compiled} in
-@file{benchmark.el}.  You can also use the @code{benchmark} command
-for timing forms interactively.
+@code{benchmark-run}, @code{benchmark-run-compiled} and
+@code{benchmark-progn} in @file{benchmark.el}.  You can also use the
+@code{benchmark} command for timing forms interactively.
 
 @c Not worth putting in the printed manual.
 @ifnottex
diff --git a/etc/NEWS b/etc/NEWS
index ff613ec..ab3bbd1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2399,6 +2399,12 @@ scrolling.
 
 * Lisp Changes in Emacs 27.1
 
++++
+** New macro 'benchmark-progn'
+This macro works like 'progn', but messages how long it takes to
+evaluate the body forms.  The value of the last form is the return
+value.
+
 ** New function 'read-char-with-history'.
 This function works like 'read-char', but maintains a history that can
 be navigated via the 'M-p'/'M-n' keystrokes.
diff --git a/lisp/emacs-lisp/benchmark.el b/lisp/emacs-lisp/benchmark.el
index 8f12858..278fb80 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]