>>>> "MB" == Martin Buchholz
<martin(a)xemacs.org> writes:
MB> (byte-compile (defun myfun ()
MB> (let ((count 10000000))
MB> (while (> count 0)
MB> (setq z (cons 1 2))
MB> (setq count (- count 1))))))
MB> (profile (myfun))
MB> (call-interactively 'profile-results))
MB> (Hrvoje, shouldn't there be a macro to encapsulate this idiom?)
I propose we add this to profile.el:
libs/xemacs-devel/ChangeLog:
2000-03-05 Martin Buchholz <martin(a)xemacs.org>
* profile.el (compile-and-profile): New.
Index: libs/xemacs-devel/profile.el
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs-packages/libs/xemacs-devel/profile.el,v
retrieving revision 1.3
diff -u -w -r1.3 profile.el
--- profile.el 2000/03/04 16:51:09 1.3
+++ profile.el 2000/03/05 08:46:18
@@ -57,6 +57,9 @@
;; buffer, go to the group buffer, and press `M-x clear-profiling-info'
;; followed by `M-x profile-key-sequence RET SPC'.
+;; A convenient higher level profiling tool is `compile-and-profile',
+;; which automatically byte-compiles code to be profiled.
+;; This makes the profiling results more meaningful.
;;; Code:
@@ -184,5 +187,15 @@
(setq keys (vector keys)))
(profile
(mapc 'dispatch-event keys)))
+
+;;;###autoload
+(defmacro compile-and-profile (&rest forms)
+ "Byte compile FORMS, profile the execution, and pretty-print the results."
+ `(progn
+ (clear-profiling-info)
+ (flet ((compiled-code-being-profiled () ,@forms))
+ (byte-compile 'compiled-code-being-profiled)
+ (call-interactively 'profile-results
+ (profile (compiled-code-being-profiled))))))
;;; profile.el ends here
The hard thing is to come up with a good name and docstring.
Use like this:
(compile-and-profile
(let ((count 100000))
(while (> count 0)
(setq z (cons 1 2))
(setq count (- count 1)))))
The current functionality in profile.el is a little too low-level.