Racket Interactive 与编译性能 [英] Racket Interactive vs Compiled Performance

查看:49
本文介绍了Racket Interactive 与编译性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否编译 Racket 程序似乎对运行时性能没有影响.

Whether or not I compile a Racket program seems to make no difference to the runtime performance.

编译改进的仅仅是文件的加载吗?换句话说,运行 racket src.rkt 是否会即时进行 jit 编译,这就是为什么我认为编译与交互式没有区别?

Is it just the loading of the file initially that is improved by compilation? In other words, does running racket src.rkt do a jit compilation on the fly, which is why I see no difference in compiling vs interactive?

即使对于整数运算的紧密循环,我认为会发生一些差异,但无论我之前是否做过 raco make,分析时间都是相同的.

Even for tight loops of integer arithmetic, where I thought some difference would occur, the profile times are equivalent whether or not I previously did a raco make.

我是否遗漏了一些简单的东西?

Am I missing something simple?

PS,我注意到我可以针对源文件 (.rkt) 或 .zo 文件运行球拍.如果找到对应于.rkt文件的球拍是否自动使用.zo,或者是否需要使用.zo文件明确的?无论哪种方式,它对我看到的性能数字都没有影响.

PS, I notice that I can run racket against the source file (.rkt) or .zo file. Does racket automatically use the .zo if one is found that corresponds to the .rkt file, or does the .zo file need to be used explicitly? Either way, it makes no difference to the performance numbers I'm seeing.

推荐答案

是的,你说得对.

Racket 分两个阶段编译代码:首先,代码被编译成字节码形式,然后在运行时被 jitt 成机器码.编译文件时,您基本上是在创建字节码,以便稍后重新编译.由于这通常不会为小段代码花费大量时间,因此您不会在运行时看到任何明显的差异.举个极端的例子,你可以删除集合树中的所有 *.zo 文件并启动 DrRacket——这将需要 很多 时间来启动,因为有很多代码,但是一旦它启动,它就会几乎像往常一样运行.(点击运行"也会很慢,因为这会重新加载并重新编译一些文件.)对于较大的代码片段的另一个问题是编译过程可能会使内存消耗更高,但这对于较小的代码片段也不是问题.

Racket compiles code in two stages: first, the code is compiled into bytecode form, and then when it runs it gets jitted into machine code. When you compile a file, you're basically creating the bytecode which saves on re-compiling it later. Since that's usually not something that takes a lot of time for small pieces of code, you won't see any noticeable difference in runtimes. For an extreme example, you can delete all *.zo files in the collection tree and start DrRacket -- it will take a lot of time to start since there's a ton of code, but once it does start, it would run almost as usual. (It would also be slow to click "run" since that will reload and recompile some files.) Another concern for bigger pieces of code is that the compilation process can make memory consumption higher, but that's also not an issue with smaller pieces of code.

另请参阅指南中的性能章节以获取有关如何改进的提示性能.

See also the Performace chapter in the guide for hints on how to improve performance.

这篇关于Racket Interactive 与编译性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆