是否有相当于 Lisp 的“运行时”的东西?方案中的原始?

发布于 2024-08-20 07:43:37 字数 571 浏览 7 评论 0原文

根据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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

征﹌骨岁月お 2024-08-27 07:43:38

如果您有符合Scheme编程语言最新规范的实现已修订< support>7 2013年发布的算法语言方案报告(R7RS),如Chibi-Scheme,您现在应该使用 R7RS 中标准化的 current-second 时间库:

(当前秒)时间库过程

返回一个不精确的数字,表示国际原子时 (TAI) 刻度上的当前时间。值 0.0 表示 1970 年 1 月 1 日 TAI 午夜(相当于世界时间午夜前 10 秒),值 1.0 表示晚 1 TAI 秒。不需要高精度,也不需要高精度;特别是,返回协调世界时加上合适的常量可能是最好的实现。

本书的一些练习 < em>计算机程序的结构和解释 (SICP) 期望以微秒为单位的运行时过程可用,因此您可以使用以下定义:

(define (runtime) (* 1000 (current-second)))

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:

(current-second) time library procedure

Returns an inexact number representing the current time on the International Atomic Time (TAI) scale. The value 0.0 represents midnight on January 1, 1970 TAI (equivalent to ten seconds before midnight Universal Time) and the value 1.0 represents one TAI second later. Neither high accuracy nor high precision are required; in particular, returning Coordinated Universal Time plus a suitable constant might be the best an implementation can do.

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:

(define (runtime) (* 1000 (current-second)))
固执像三岁 2024-08-27 07:43:37

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.

随心而道 2024-08-27 07:43:37

我今天也遇到了这个问题。我正在使用 DrRacket,因为它似乎已经取代了 DrScheme。虽然这是一个旧线程,但我正在为任何偶然发现该线程的新人添加我的发现。

使用 R5RS (#lang r5rs) 作为所选语言,在程序前添加以下两行以使其运行

(#%require (only racket/base current-milliseconds))
(define (runtime) (current-milliseconds))

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

(#%require (only racket/base current-milliseconds))
(define (runtime) (current-milliseconds))
墨离汐 2024-08-27 07:43:37

您可以使用 包含运行时定义。

这是软件包描述。

这里是安装说明:

  • 打开包管理器:在 DrRacket 中选择菜单文件,然后选择包管理器...

  • 在选项卡中Do What I Mean找到文本字段并输入:sicp

  • 最后单击安装按钮。

现在您可以从 SICP 调用 runtime 和其他过程:

#lang sicp
(runtime)

预期输出如下:

1606611898030115
> 

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:

#lang sicp
(runtime)

An expected output would be like this:

1606611898030115
> 
杀手六號 2024-08-27 07:43:37

我正在使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文