简体   繁体   English

为Ruby 2.0配置Rails

[英]Configuring Rails for Ruby 2.0

Ruby 2.0 has been released, see: Ruby 2.0已经发布,请参阅:

http://www.ruby-lang.org/en/news/2013/02/24/ruby-2-0-0-p0-is-released/ http://www.ruby-lang.org/en/news/2013/02/24/ruby-2-0-0-p0-is-released/

What changes to my Rails App/Installation should I anticipate making after upgrading my system to Ruby 2.0? 在将系统升级到Ruby 2.0后,我预计会对我的Rails App / Installation进行哪些更改?

So here's what I had to do after upgrading. 所以这是升级后我必须做的事情。

Bundler 1.2.x is not compatible, it raises an error saying to upgrade to >= 1.3, which is not yet release. Bundler 1.2.x不兼容,它引发了一个错误,说升级到> = 1.3,尚未发布。 So if you are using RVM, jump into your global gemset for the 2.0 ruby and upgrade to 1.3.pre version until 1.3.0 is released. 因此,如果您正在使用RVM,请跳转到2.0 ruby​​的全局gemset并升级到1.3.pre版本,直到1.3.0发布。 Also it seems like there's something up with the rubygems api. 似乎还有rubygems api的东西。 My bundle install did not use the new API, instead doing the old 'fetch index' method, which of course takes a little bit longer. 我的bundle install没有使用新的API,而是使用旧的'fetch index'方法,这当然需要更长的时间。

Aside from that, my bundle did install cleanly, and my full set of spec tests completed with all OK. 除此之外,我的软件包确实安装得很干净,我的全套规范测试都完成了。 I did some timing tests to see how much the rails load time has improved. 我做了一些时序测试,看看导轨加载时间有多大改善。

# Using 1.9.3-p327

RSpec Time: 24.87s
Wall Time : 34.40s
Load Time :  9.53s

# Using 2.0.0-p0

RSpec Time: 22.49s (90.4%)
Wall Time : 26.89s (78.2%)
Load Time :   4.4s (46.2%)

Obviously the load time for rspec is a little heavier with all of the testing gems, but still over a 50% drop in load time and a 10% drop in test run time is nice. 显然,对于所有测试宝石来说,rspec的加载时间稍长一些,但是加载时间仍然超过50%,并且测试运行时间下降10%。

I did a similar test using rails runner 'puts User.count' which would skip the test bootstrapping. 我使用rails runner 'puts User.count'进行了类似的测试,这将跳过测试引导。

1.9.3 : 7.27s
2.0.0 : 3.36s (46.2%)

Again, nice drop of over 50% :) 再次,超过50%的好下降:)

Kind of getting off track here... new toys do that I guess, but it seems like the only change I had to make was upgrading to a pre-release bundler. 有点偏离这里...我猜想新的玩具,但似乎我必须做的唯一改变是升级到预发行捆绑器。

Here's another test of different iterators 这是对不同迭代器的另一个测试

$ rvm 1.9.3-p327,2.0.0-p0 --verbose do ruby test.rb
ruby-1.9.3-p327: ruby 1.9.3p327 (2012-11-10 revision 37606) [i686-linux] 
       user     system      total        real
for    0.610000   0.000000   0.610000 (  0.607189)
times  0.580000   0.000000   0.580000 (  0.587303)
upto   0.590000   0.000000   0.590000 (  0.585730)
each   0.590000   0.000000   0.590000 (  0.593494)
ruby-2.0.0-p0: ruby 2.0.0p0 (2013-02-24 revision 39474) [i686-linux] 
       user     system      total        real
for    0.590000   0.000000   0.590000 (  0.582743)
times  0.560000   0.000000   0.560000 (  0.565961)
upto   0.560000   0.000000   0.560000 (  0.562400)
each   0.570000   0.000000   0.570000 (  0.573469)

Marginal, about a 4-5% gain. 边际,收益率约为4-5%。

More interesting is this, calling Object.new 500 million times 更有趣的是,将Object.new称为5亿次

1.9.3 : 129.063s
2.0.0 :  97.234s

About a 25% drop in object creation time. 对象创建时间减少约25%。

I started a new project with rails 4 and ruby 2.0. 我用rails 4和ruby 2.0开始了一个新项目。 This is how I did it. 这就是我做到的。

First, I set RVM to Ruby 2.0. 首先,我将RVM设置为Ruby 2.0。

Then installed bundler 1.3: 然后安装捆绑器1.3:

$ gem install bundler

Updated these gems and 'bundle install'. 更新了这些宝石和'捆绑安装'。

gem 'rails',     :git => 'git://github.com/rails/rails.git'
gem 'journey',   :git => 'git://github.com/rails/journey.git'
gem 'arel',      :git => 'git://github.com/rails/arel.git'

group :assets do
  gem 'sass-rails',   :git => 'git://github.com/rails/sass-rails.git'
  gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git'
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM