是否有相当于 Lisp 的“运行时”的东西?方案中的原始?
根据SICP 第 1.2.6 节< /a>,练习 1.22:
大多数 Lisp 实现都包含一个称为运行时的原语,它返回一个整数,指定系统已运行的时间量(例如,以微秒为单位进行测量)。
我正在使用 DrScheme,其中运行时似乎不可用,所以我寻找一个好的替代品。我在 PLT-Scheme Reference 中发现有一个 当前毫秒 原语。有谁知道Scheme中是否有分辨率更好的计时器?
According to SICP section 1.2.6, exercise 1.22:
Most Lisp implementations include a primitive called runtime that returns an integer that specifies the amount of time the system has been running (measured, for example, in microseconds).
I'm using DrScheme, where runtime doesn't seem to be available, so I'm looking for a good substitute. I found in the PLT-Scheme Reference that there is a current-milliseconds primitive. Does anyone know if there's a timer in Scheme with better resolution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您有符合Scheme编程语言最新规范的实现已修订< support>7 2013年发布的算法语言方案报告(R7RS),如Chibi-Scheme,您现在应该使用 R7RS 中标准化的
current-second
时间库:本书的一些练习 < em>计算机程序的结构和解释 (SICP) 期望以微秒为单位的
运行时
过程可用,因此您可以使用以下定义:If you have an implementation that is conformant with the latest specification of the Scheme programming language Revised7 Report on the Algorithmic Language Scheme (R7RS) published in 2013, such as Chibi-Scheme, you should now use the
current-second
time library which was standardised in R7RS:Some exercises of the book Structure and Interpretation of Computer Programs (SICP) expect a
runtime
procedure measured in microseconds to be available, so you can use this definition:current-milliseconds
是一个从系统返回当前毫秒计数的函数,但它可能会减少。current-inexact-milliseconds
类似,但返回保证增加的浮点数。您还可以在该页面上找到一堆类似的函数,但如果您需要的只是对某个函数进行计时,那么只需使用 (
时间
expr),它将打印出计算表达式所花费的时间。
此处相关的另一件事是 分析器,以防您需要更多对代码进行详细分析。
current-milliseconds
is a function that returns the current millisecond count from the system, but it might decrease.current-inexact-milliseconds
is similar, but returns a guaranteed-to-increase floating point number.There are also a bunch of similar functions that you can find on that page, but if all you need is to time a certain function, then just use (
time
expr) and it will print out the time it took to evaluate the expression.Another thing that is relevant here is the profiler, in case you need some more verbose analysis of your code.
我今天也遇到了这个问题。我正在使用 DrRacket,因为它似乎已经取代了 DrScheme。虽然这是一个旧线程,但我正在为任何偶然发现该线程的新人添加我的发现。
使用 R5RS (
#lang r5rs
) 作为所选语言,在程序前添加以下两行以使其运行I too came across this problem today. I am using DrRacket, as it seems to have superseded DrScheme. Though this is an old thread, I am adding my findings for anyone new who stumbles across this thread.
With R5RS (
#lang r5rs
) as selected language, add following two lines before the program to make it work您可以使用 包含
运行时
的定义。这是软件包描述。
这里是安装说明:
打开包管理器:在 DrRacket 中选择菜单文件,然后选择包管理器...。
在选项卡中Do What I Mean找到文本字段并输入:
sicp
最后单击安装按钮。
现在您可以从 SICP 调用
runtime
和其他过程:预期输出如下:
You can use the package sicp that contains definition of the
runtime
.Here is the package description.
And here is the installation instructions:
Open the Package Manager: in DrRacket choose the menu File then choose Package Manager….
In the tab Do What I Mean find the text field and enter:
sicp
Finally click the Install button.
Now you can call
runtime
and other procedures from SICP:An expected output would be like this:
我正在使用 mit-scheme 进行 SICP,并发现毫秒是由
(real-time-clock)
根据 用户手册。I'm using mit-scheme to do SICP and have found that milliseconds is given by
(real-time-clock)
as per the user manual.