home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / lisp / 3308 < prev    next >
Encoding:
Text File  |  1993-01-23  |  2.0 KB  |  55 lines

  1. Xref: sparky comp.lang.lisp:3308 comp.lang.lisp.mcl:2065
  2. Newsgroups: comp.lang.lisp,comp.lang.lisp.mcl
  3. Path: sparky!uunet!cs.utexas.edu!torn!nott!bnrgate!bcars267!bcars267!emcoop
  4. From: emcoop@bnr.ca (hume smith)
  5. Subject: Re: Measuring elapsed CPU time
  6. In-Reply-To: joungwoo@mensa.usc.edu's message of 21 Jan 1993 01:43:08 -0800
  7. Message-ID: <EMCOOP.93Jan21091840@bcars148.bnr.ca>
  8. Sender: news@bnr.ca (usenet)
  9. Nntp-Posting-Host: bcars148
  10. Organization: Bell-Northern Research, Ottawa, Canada
  11. References: <1jlr7cINNep1@mensa.usc.edu>
  12. Date: Thu, 21 Jan 1993 14:18:40 GMT
  13. Lines: 40
  14.  
  15. In article <1jlr7cINNep1@mensa.usc.edu> joungwoo@mensa.usc.edu (John Kim) writes:
  16.  
  17.        So I tried using builtin function GET-INTERNAL-RUN-TIME as follows,
  18.    but the following function defined by me usually it gives me either 0 or 1 no
  19.    matter how time-consuming task I give it. 
  20.  
  21.    (defun CPU-time (form)
  22.      "returns the actual elapsed CPU(?) time not including I/O processing 
  23.    in msecs.
  24.    "
  25.      (let ((start-time nil)
  26.        (end-time nil)
  27.        )
  28.        (setq start-time (get-internal-run-time))
  29.        form
  30.        (setq end-time (get-internal-run-time))
  31.        (print start-time)
  32.        (print end-time)
  33.        (- end-time start-time)
  34.        ))
  35.  
  36.    Am I doing something wrong in the above function definition or is there a
  37.    better way to do this?
  38.  
  39. this sort of thing needs a macro.  in your construct, the form has been evaled by the time
  40. the function starts, and all your timer ends up timing is how long it takes the
  41. evaluator to find the value of the symbol "form".  try this:
  42.  
  43. (defmacro CPU-time (form)
  44.   `(let (start-time end-time)
  45.      (setq start-time (get-internal-run-time))
  46.      ,form
  47.      (setq end-time (get-internal-run-time))
  48.      (print start-time)
  49.      (print end-time)
  50.      (- end-time start-time)))
  51. --
  52. Hume Smith                                Honour sick and davey cris-cross
  53. hume.smith@acadiau.ca                     McTruloff sentimie
  54. emcoop@bnr.ca                             A parsnip inner pair threes.
  55.