我正在寻找一些帮助来测量使用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)))))
Run Code Online (Sandbox Code Playgroud)
它的使用方式如下:
(measure-time
(dotimes (i 100000)
(1+ 1)))
Run Code Online (Sandbox Code Playgroud)
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) ))))
Run Code Online (Sandbox Code Playgroud)