如何编译Ruby? [英] How to compile Ruby?

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

问题描述

有没有工具,可以让我编译Ruby代码,使其运行更快?

Is there a tool that can allow me to compile Ruby code so that it runs somewhat faster?

例如,我听说有一个称为pyc的工具,它允许我们编译代码,使其运行速度提高10倍。 p>

For example, I have heard that there is a tool for Python called "pyc" that allows us to compile the code, so that it runs 10 times faster.

推荐答案

简单的答案是,你不能,至少用MRI 1.8(标准)。这是因为1.8通过走抽象语法树来工作。 Python,Ruby 1.9,JRuby和Rubinius使用字节码,这允许编译中间表示(字节码)。

The simple answer is that you can't, at least with MRI 1.8 (the standard). This is because 1.8 works by walking the Abstract Syntax Tree. Python, Ruby 1.9, JRuby, and Rubinius use byte code, which allows compilation to an Intermediate Representation (byte code).

使用Rubinius,本文: http://rubini.us/2011/03 / 17 / run-ruby-with-no-ruby /

With Rubinius, you can do something as described in this post: http://rubini.us/2011/03/17/running-ruby-with-no-ruby/

在JRuby中,你可以使用Ahead Of Time编译器,相信jrubyc 。

In JRuby you can use the "Ahead Of Time" compiler through, I believe, jrubyc.

这不是真正的做事的标准方式,你通常最好只是让你的Ruby实现处理它喜欢它。 Rubinius至少会在第一次编译之后缓存字节码,根据需要更新它。

This isn't really the standard way of doing things and you're generally better off just letting your Ruby implementation handle it like it wants to. Rubinius, at least, will cache byte code after the first compilation, updating it as it needs to.

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

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