我需要一些帮助来测量一个使用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
来避免此类变量捕获。 - Musa Al-hassy