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

  1. Xref: sparky comp.lang.lisp:3352 comp.lang.lisp.mcl:2086
  2. Path: sparky!uunet!usc!usc!not-for-mail
  3. From: joungwoo@mensa.usc.edu (John Kim)
  4. Newsgroups: comp.lang.lisp,comp.lang.lisp.mcl
  5. Subject: Re: Measuring elapsed CPU time
  6. Date: 24 Jan 1993 18:47:34 -0800
  7. Organization: University of Southern California, Los Angeles, CA
  8. Lines: 65
  9. Message-ID: <1jvkc6INN10n@mensa.usc.edu>
  10. References: <1jlr7cINNep1@mensa.usc.edu>
  11. NNTP-Posting-Host: mensa.usc.edu
  12. Keywords: CPU time
  13.  
  14. I would like to thank everyone who emailed me or posted an answer on this BB
  15. for an elementary question. (I knew lisp function's args are evaled first,
  16. but the fact just slipped out when I was doing my coding.:-]) I could have
  17. guessed using defmacro. But many of your alternative answers were extensive
  18. and beyond just using macros.
  19.  
  20. Frankly I have received ENOUGH answers by now. I'll post a summary soon.
  21.  
  22. Thank you all again. Netters are wonderful.
  23.  
  24. John
  25.  
  26.  
  27.  
  28. joungwoo@mensa.usc.edu (John Kim) writes:
  29.  
  30.  
  31. >I'm trying to measure teh elasped CPU time during a lisp form has been run.
  32. >The problem with the Common Lisp's builtin function TIME is that it does not
  33. >return the various elapsed times but returns the return value of the form
  34. >(ie, TIME's arg) plus I don't know if I am getting accurate elapsed CPU time
  35. >either. 
  36. >    So I tried using builtin function GET-INTERNAL-RUN-TIME as follows,
  37. >but the following function defined by me usually it gives me either 0 or 1 no
  38. >matter how time-consuming task I give it. 
  39.  
  40. >(defun CPU-time (form)
  41. >  "returns the actual elapsed CPU(?) time not including I/O processing 
  42. >in msecs.
  43. >"
  44. >  (let ((start-time nil)
  45. >        (end-time nil)
  46. >        )
  47. >    (setq start-time (get-internal-run-time))
  48. >    form
  49. >    (setq end-time (get-internal-run-time))
  50. >    (print start-time)
  51. >    (print end-time)
  52. >    (- end-time start-time)
  53. >    ))
  54.  
  55. >Am I doing something wrong in the above function definition or is there a
  56. >better way to do this? Or are most tasks heavily I/O bound but so lightly
  57. >CPU-bound that the internal clock for GET-INTERNAL-RUN-TIME hardly ticks?
  58.  
  59. >Thank you in advance. (Please email me.)
  60.  
  61. >John
  62.  
  63. >P.S. I tried both Lucid Common Lisp/Sparc on Sun and Macintosh Common Lisp
  64. >(MCL 2.0) and the result is the same.
  65.  
  66. >P.P.S. In the worst case, is there a way to print the msg (not the return
  67. >value) of TIME which goes to *TRACE-OUTPUT* to a string (so I can parse teh
  68. >string later)?
  69. >-- 
  70. >Joung-woo John Kim                joungwoo@mensa.usc.edu
  71. >Computer Science Dept.
  72. >University of Southern California, Los Angeles, CA 90089-0781
  73.  
  74. -- 
  75. Joung-woo John Kim                joungwoo@mensa.usc.edu
  76. Computer Science Dept.
  77. University of Southern California, Los Angeles, CA 90089-0781
  78.  
  79.