From xemacs-m  Sun Jun 22 17:27:55 1997
Received: from jagor.srce.hr (hniksic@jagor.srce.hr [161.53.2.130])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id RAA19644
	for <xemacs-beta@xemacs.org>; Sun, 22 Jun 1997 17:27:53 -0500 (CDT)
Received: (from hniksic@localhost)
          by jagor.srce.hr (8.8.5/8.8.4)
	  id AAA01602; Mon, 23 Jun 1997 00:27:54 +0200 (MET DST)
To: XEmacs Developers <xemacs-beta@xemacs.org>
Subject: [PATCH] Addition to profile.el
X-Attribution: Hrv
X-Face: Mie8:rOV<\c/~z{s.X4A{!?vY7{drJ([U]0O=W/<W*SMo/Mv:58:*_y~ki>xDi&N7XG
        KV^$k0m3Oe/)'e%3=$PCR&3ITUXH,cK>]bci&<qQ>Ff%x_>1`T(+M2Gg/fgndU%k*ft
        [(7._6e0n-V%|%'[c|q:;}td$#INd+;?!-V=c8Pqf}3J
From: Hrvoje Niksic <hniksic@srce.hr>
Date: 23 Jun 1997 00:27:54 +0200
Message-ID: <kigafkiqnmd.fsf@jagor.srce.hr>
Lines: 50
X-Mailer: Gnus v5.4.59/XEmacs 20.3(beta8) - "Copenhagen"

I have added the `profile' macro, to evaluate the given forms while
profiling them.  I've found it quite useful.


1997-06-23  Hrvoje Niksic  <hniksic@srce.hr>

	* prim/profile.el (profile): New macro.


--- lisp/prim/profile.el.orig	Sun Jun 22 22:12:05 1997
+++ lisp/prim/profile.el	Sun Jun 22 22:25:34 1997
@@ -38,15 +38,27 @@
   (setq info (nreverse (sort info #'cdr-less-than-cdr)))
   (princ "Function                                               Count        %\n")
   (princ "---------------------------------------------------------------------\n")
-  (let ((sum 0.0)
-	(info2 info))
-    (while info2
-      (setq sum (+ sum (cdar info2)))
-      (setq info2 (cdr info2)))
+  (let ((sum 0.0))
+    (dolist (info2 info)
+      (incf sum (cdr info2)))
     (while info
       (let ((f (caar info)))
 	(princ (format "%-50s%10d   %6.3f\n" f (cdar info)
 		       (* 100 (/ (cdar info) sum)))))
       (setq info (cdr info)))))
+
+;;;###autoload
+(defmacro profile (&rest forms)
+  "Turn on profiling, execute FORMS and stop profiling.
+Returns the profiling info, printable by `pretty-print-profiling-info'."
+  `(progn
+     (unwind-protect
+	 (progn
+	   (start-profiling)
+	   ,@forms)
+       (stop-profiling))
+     (get-profiling-info)))
+
+(put 'profile 'lisp-indent-function 0)
 
 ;;; profile.el ends here


-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
Idle RAM is the Devil's playground.

