我正在寻找一些帮助,请,来测量使用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) ))))发布于 2014-05-13 04:48:24
和你引用的例子完全一样。你真的把(measure-time ... )围绕着你的时间安排。在您的例子中,整个catch表达式。
你没试过吗?
发布于 2021-05-23 15:39:46
顺便说一下,这个宏在Emacs中称为benchmark-elapse,但它不是自动加载的,所以在使用它之前需要(require 'benchmark)。
https://stackoverflow.com/questions/23622296
复制相似问题