Time Code in PLT-Scheme

空扰寡人 提交于 2019-12-06 10:33:10

The standard name for timing the execution of expressions in most Scheme implementations is "time". Here is an example from within DrRacket.

(define (loopy times) (if (zero? times) 0 (loopy (sub1 times))))

(time (loopy 5000000)) cpu time: 1526 real time: 1657 gc time: 0 0

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:

  • (time-apply proc arg-list) invokes the procedure proc with the arguments in arg-list. Four values are returned: a list containing the result(s) of applying proc, the number of milliseconds of CPU time required to obtain this result, the number of ``real'' milliseconds required for the result, and the number of milliseconds of CPU time (included in the first result) spent on garbage collection.

Example usage:

> (time-apply loopy '(5000000))
(0)
621
887
0
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!