Yes, I am aware of the emacs profiler feature. I'm looking for something similar to the time
keyword in bash, something like:
(time (myfunc))
which would return or print the time taken by the myfunc
call. Is there such a thing?
benchmark.el provides benchmark-run
and benchmark-run-compiled
functions as well as a benchmark
version to run interactively. The linked example:
C-u 512 M-x benchmark (sort (number-sequence 1 512) '<) Elapsed time: 0.260000s (0.046000s in 6 GCs)
The timer used by all those functions is the benchmark-elapse
macro, which you can also use directly if desired:
ELISP> (require 'benchmark)
ELISP> (benchmark-elapse
(sit-for 2))
2.00707889
I found exactly what I was looking for at http://nullprogram.com/blog/2009/05/28/
(defmacro measure-time (&rest body)
"Measure and return the running time of the code block."
(declare (indent defun))
(let ((start (make-symbol "start")))
`(let ((,start (float-time)))
,@body
(- (float-time) ,start))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With