是的,我知道emacs分析器功能。我正在寻找像在bash类似time
关键字的东西,东西:有没有简单的方法来在elisp中调用函数?
(time (myfunc))
这将返回或打印由myfunc
调用所花费的时间。有这样的事吗?
是的,我知道emacs分析器功能。我正在寻找像在bash类似time
关键字的东西,东西:有没有简单的方法来在elisp中调用函数?
(time (myfunc))
这将返回或打印由myfunc
调用所花费的时间。有这样的事吗?
快速搜索显示benchmark.el,它提供benchmark-run
和benchmark-run-compiled
函数以及benchmark
版本以交互方式运行。链接的例子:
C-u 512 M-x benchmark (sort (number-sequence 1 512) '<) Elapsed time: 0.260000s (0.046000s in 6 GCs)
所有这些功能使用的定时器是benchmark-elapse
宏,它如果需要的话,你也可以直接使用:
ELISP> (require 'benchmark)
ELISP> (benchmark-elapse
(sit-for 2))
2.00707889
我发现正是我一直在http://nullprogram.com/blog/2009/05/28/
寻找(defmacro measure-time (&rest body) "Measure and return the running time of the code block." (declare (indent defun)) (let ((start (make-symbol "start"))) `(let ((,start (float-time))) ,@body (- (float-time) ,start))))
你能解释为什么这比'benchmark-run'更好吗? – phils
重量更轻。我正在寻找一些超级简单的东西。 – killdash9
然后你可以使用'benchmark-elapse'。我已经将它添加到Jon的答案中。 – phils