Function: benchmark-progn

benchmark-progn is an autoloaded macro defined in benchmark.el.gz.

Signature

(benchmark-progn &rest BODY)

Documentation

Evaluate BODY and message the time taken.

The return value is the value of the final form in BODY.

Probably introduced at or before Emacs version 27.1.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/benchmark.el.gz
;;;###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 t) (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)))