[comp.emacs] profiler

merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) (05/19/89)

In article <40509@think.UUCP>, barmar@think (Barry Margolin) writes:
| In article <8905111747.AA17268@dsys.icst.nbs.gov> rbj@dsys.icst.nbs.GOV (Root Boy Jim) writes:
[rbj's version deleted]
| Here's a version that works around midnight:
[barmar's version deleted]

OK, I'll throw my response into the ring:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; snip snip
(defun seconds-past-midnight ()
  "Return seconds past midnight."
  (let ((time (current-time-string)))
    (+ (* 3600 (string-to-int (substring time 11 13)))
       (* 60 (string-to-int (substring time 14 16)))
       (string-to-int (substring time 17 19)))))

(defun profile (func count)
  "Evaluate FUNC COUNT times, and return the number of wall-clock seconds."
  (let ((start-time (seconds-past-midnight))
	(i count))
    (while (>= (setq i (1- i)) 0)
      (eval func))
    (% (- (seconds-past-midnight) start-time -86400) 86400)))

(defun profile-it (func count)
  "Evaluate FUNC COUNT times, displaying the result."
  (interactive "xProfile Expression: \np")
  (message "profiling...")
  (message "%d iterations took %d seconds" count (profile func count)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; snip snip

This version of "seconds-past-midnight" is faster than rbj's
equivalent function (according to the profiler) <grin>.  Apparently,
the more parens you have in a function, the longer it takes to run it,
no matter *what* you do <sigh>.

Just another Elisp hacker (last day, I think...)
-- 
***** PLEASE IGNORE THE ADDRESS IN THE HEADER *****
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095===\
{ <merlyn@agora.hf.intel.com> ...!uunet!agora.hf.intel.com!merlyn    }
\=Cute quote: "Welcome to Oregon... home of the California Raisins!"=/

rbj@dsys.ncsl.nist.GOV (Root Boy Jim) (06/08/89)

? This version of "seconds-past-midnight" is faster than rbj's

Touche!

	Root Boy Jim is what I am
	Are you what you are or what?