【发布时间】:2014-05-13 03:24:50
【问题描述】:
我正在寻求帮助,以便在使用 while 循环时测量函数调用的时间——即,当函数抛出完成时时钟应该停止。我在邮件列表中找到了以下计时器:http://lists.gnu.org/archive/html/help-gnu-emacs/2008-06/msg00087.html
(defmacro measure-time (&rest body)
"Measure the time it takes to evaluate BODY."
`(let ((time (current-time)))
,@body
(message "%.06f" (float-time (time-since time)))))
它是这样使用的:
(measure-time
(dotimes (i 100000)
(1+ 1)))
非常感谢您提供如何使用带有while 循环的计时器宏的示例。我正在寻找从while 循环开始之前到done 被抛出时结束的总时间。
(defun test ()
(measure-time)
(catch 'done
(while t
[*** do a bunch of stuff]
(when (condition-satisfied-p)
[*** STOP THE CLOCK AND PRINT TOTAL DURATION ***]
(throw 'done nil) ))))
【问题讨论】:
-
请注意,如果
body包含符号time,您将得到意想不到的结果。您可以使用gensym避免此类变量捕获。