PLT 方案中的时间码
我想看看一个函数运行需要多长时间。 在 PLT-Scheme 中执行此操作的最简单方法是什么? 理想情况下,我希望能够做这样的事情:
> (define (loopy times)
(if (zero? times)
0
(loopy (sub1 times))))
> (loopy 5000000)
0 ;(after about a second)
> (timed (loopy 5000000))
Took: 0.93 seconds
0
>
如果我必须使用其他语法,例如 (timed Loopy 5000000)
或 (timed '( Loopy 5000000))
,或者如果它返回 cons 或其他内容所花费的时间。
I want to see how long a function takes to run. What's the easiest way to do this in PLT-Scheme? Ideally I'd want to be able to do something like this:
> (define (loopy times)
(if (zero? times)
0
(loopy (sub1 times))))
> (loopy 5000000)
0 ;(after about a second)
> (timed (loopy 5000000))
Took: 0.93 seconds
0
>
It doesn't matter if I'd have to use some other syntax like (timed loopy 5000000)
or (timed '(loopy 5000000))
, or if it returns the time taken in a cons or something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在大多数Scheme 实现中计时表达式执行的标准名称是“时间”。 这是 DrRacket 内部的一个示例。
如果您花时间对不同的实现进行相互比较,
记住从命令行使用racket而不是直接进行基准测试
在 DrRacket 中(DrRacket 插入调试代码以便提供更好的错误消息)。
The standard name for timing the execution of expressions in most Scheme implementations is "time". Here is an example from within DrRacket.
If you use time to benchmark different implementations against each other,
remember to use racket from the command line rather than benchmarking directly
in DrRacket (DrRacket inserts debug code in order to give better error messages).
找到它...
来自 在线文档:
用法示例:
Found it...
From the online documentation:
Example usage: