To profile Elisp code, I tried benchmark.el and some profiler--prefixed built-in functions.

But all their reports are either non-human-readable or inadequate.

I think the ideal outcome is like what the time macro does in Common Lisp:

CL-USER> (time
          (print "Hello, world!"))

"Hello, world!" 
Evaluation took:
  0.000 seconds of real time
  0.000000 seconds of total run time (0.000000 user, 0.000000 system)
  100.00% CPU
  154,266 processor cycles
  0 bytes consed
"Hello, world!"

It gives real/run/user/system time, the number of processor cycles, bytes consed (memory usage), etc.

Is there any way to do that (or just a part of it)?

  • emacs.stackexchange.com/tags/elisp/info
    – Drew
    Mar 4, 2023 at 19:36
  • 1
    Please make your question self-contained. Specify what you mean by "like the Time in Common Lisp". Readers shouldn't need to go look for what Time means in Common Lisp, and then guess what you might mean by "like" Time. Just what parts of the output you show are you looking for - what does "like" mean here?
    – Drew
    Mar 4, 2023 at 19:38
  • 1
    @Drew: Thank you for the feedback; the description of the question is updated now.
    – shynur
    Mar 4, 2023 at 19:47

1 Answer 1


Is there any way to do that

Certainly. The Emacs source code is in a Git repository at https://savannah.gnu.org/projects/emacs/, and the license allows you to add any features to it that you want, for any reason you might have.

The most common method for getting the cycle count is to use the RDTSC or RDTSCP instructions. However, a more useful number would be the instruction count, rather than the cycle count. Even better if you can count cache misses and IPC as well. Both Intel and AMD CPUs have performance counters that track this information, so with some elbow grease you should be able to do it. I leave it as an exercise to the reader.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.