diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-30 09:17:48 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-30 09:17:48 -0500 |
| commit | 982d090069354ef64568359c3e62dbfed274b942 (patch) | |
| tree | 83dda24f094e0993295a082118e0d24e7f85268c | |
| parent | 6930a43643dc0848a5711578f96a06c342c2281c (diff) | |
| download | dotemacs-982d090069354ef64568359c3e62dbfed274b942.tar.gz dotemacs-982d090069354ef64568359c3e62dbfed274b942.zip | |
refactor(config-utilities): extract cj/--benchmark-method
Splits the timer dispatch out of cj/benchmark-this-method so it can
be tested with a known method symbol instead of going through
read-string + completing-read. The interactive wrapper still prompts
for both inputs, and now catches the user-error from the internal so
the user-facing behaviour on invalid input is unchanged (the message
goes to the echo area).
Returns the funcall's value to the caller, which is observable
through the timer.
| -rw-r--r-- | modules/config-utilities.el | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/modules/config-utilities.el b/modules/config-utilities.el index e4d0cf69..64d0b17d 100644 --- a/modules/config-utilities.el +++ b/modules/config-utilities.el @@ -61,17 +61,25 @@ time is displayed." (float-time (time-subtract (current-time) ,nowvar)))) (message "%s... done (%.3fs)" ,title elapsed)))))) +(defun cj/--benchmark-method (title method-symbol) + "Time the execution of METHOD-SYMBOL with display TITLE. +Returns the value returned by METHOD-SYMBOL. +Signals `user-error' if METHOD-SYMBOL is nil or not fboundp." + (unless (and method-symbol (fboundp method-symbol)) + (user-error "Invalid method: %s" method-symbol)) + (with-timer title + (funcall method-symbol))) + (defun cj/benchmark-this-method () "Prompt for a title and method name, then time the execution of the method." (interactive) - (let ((title (read-string "Enter the title for the timing: ")) - (method-name (completing-read "Enter the method name to time: " obarray - #'fboundp t))) - (let ((method-symbol (intern-soft method-name))) - (if (and method-symbol (fboundp method-symbol)) - (with-timer title - (funcall method-symbol)) - (message "Invalid method name: %s" method-name))))) + (let* ((title (read-string "Enter the title for the timing: ")) + (method-name (completing-read "Enter the method name to time: " obarray + #'fboundp t)) + (method-symbol (intern-soft method-name))) + (condition-case err + (cj/--benchmark-method title method-symbol) + (user-error (message "%s" (error-message-string err)))))) (keymap-set cj/debug-config-keymap "b" #'cj/benchmark-this-method) ;;; ----------------------------- Config Compilation ---------------------------- |
