Add new macro `benchmark-progn'
* doc/lispref/debugging.texi (Profiling): Mention it. * lisp/emacs-lisp/benchmark.el (benchmark-progn): New macro.
This commit is contained in:
parent
7acc621e37
commit
ddc9837bf4
3 changed files with 33 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue