From 982d090069354ef64568359c3e62dbfed274b942 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 30 Apr 2026 09:17:48 -0500 Subject: 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. --- modules/config-utilities.el | 24 ++++++++++++++++-------- 1 file 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 ---------------------------- -- cgit v1.2.3