Function: benchmark-call

benchmark-call is an autoloaded and byte-compiled function defined in benchmark.el.gz.

Signature

(benchmark-call FUNC &optional REPETITIONS)

Documentation

Measure the run time of calling FUNC a number REPETITIONS of times.

The result is a list (TIME GC GCTIME) where TIME is the total time it took, in seconds. GCTIME is the amount of time that was spent in the GC and GC is the number of times the GC was called.

REPETITIONS can also be a floating point number, in which case it specifies a minimum number of seconds that the benchmark execution should take. In that case the return value is prepended with the number of repetitions actually used.

Probably introduced at or before Emacs version 28.1.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/benchmark.el.gz
;;;###autoload
(defun benchmark-call (func &optional repetitions)
  "Measure the run time of calling FUNC a number REPETITIONS of times.
The result is a list (TIME GC GCTIME)
where TIME is the total time it took, in seconds.
GCTIME is the amount of time that was spent in the GC
and GC is the number of times the GC was called.

REPETITIONS can also be a floating point number, in which case it
specifies a minimum number of seconds that the benchmark execution
should take.  In that case the return value is prepended with the
number of repetitions actually used."
  (if (floatp repetitions)
      (benchmark--adaptive func repetitions)
    (unless repetitions (setq repetitions 1))
    (let ((gc gc-elapsed)
	  (gcs gcs-done)
	  (empty-func (lambda () 'empty-func)))
      (list
       (if (> repetitions 1)
	   (- (benchmark-elapse (dotimes (_ repetitions) (funcall func)))
	      (benchmark-elapse (dotimes (_ repetitions) (funcall empty-func))))
	 (- (benchmark-elapse (funcall func))
            (benchmark-elapse (funcall empty-func))))
       (- gcs-done gcs)
       (- gc-elapsed gc)))))