The Profiler

Profiling a program is the process of figuring out how much time different parts of it take to run, presumably in a quest to make it more efficient. Barry Warsaw has written an ingenious package for profiling Emacs Lisp called ELP.

Like Edebug, ELP relies on functions being "instrumented." This is done with the command elp-instrument-function, which prompts for a function name. There's also elp-instrument-package, which prompts for a prefix. Any existing functions whose names begin with the given prefix will get instrumented.

Functions are uninstrumented with elp-restore-function and elp-restore-all.

To use ELP, simply run your program after instrumenting the functions you wish to profile. Profiling data will accumulate silently. When you're ready to see the results so far, run the command elp-results. A buffer will appear, showing, for each profiled function, the number of times it was called, the total time spent in the function, and the average time per call.

Use elp-reset-function to set a function's call-count and elapsed-time counters back to zero; elp-reset-all does this for all profiles functions.

Get Writing GNU Emacs Extensions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.