【问题标题】:Why do my rspec tests run slower in Ruby 1.9.2 than 1.8.7?为什么我的 rspec 测试在 Ruby 1.9.2 中比 1.8.7 运行得慢?
【发布时间】:2012-01-15 10:22:37
【问题描述】:

我正在使用spork 测试 Sinatra 应用程序,使用 Ruby 1.9.2 的测试运行时间约为 3.5 秒,但在 Ruby 1.8.7 中它们平均为 1.2 秒。我确实尝试过 Ruby 1.9.3 甚至 JRuby,但他们对我正在使用的 gem 有一些错误。有没有办法将 Ruby 1.9.2 的 rspec 性能提升到 1.8.7 的水平?

我的宝石文件:

source :rubygems
gem 'sinatra', '1.3.1'
gem 'thin', '1.3.1'
gem 'haml', '3.1.4'
gem 'datamapper', '1.2.0'
gem 'dm-postgres-adapter', '1.2.0'
gem 'carrierwave', '0.5.8'
gem 'carrierwave-datamapper', '0.2.0'

group :test do
  gem "dm-sqlite-adapter"
  gem "spork"
  gem "rspec"
  gem "rack-test"
end

spec_helper.rb:

require 'rubygems'
require 'spork'
require 'sinatra'
require 'rack/test'
require 'rspec'

require File.join(File.dirname(__FILE__), '..', 'app.rb')
require File.join(File.dirname(__FILE__), '..', 'model/model.rb')

Spork.prefork do
  set :environment, :test
  set :files, "test_files"
end

Spork.each_run do
  RSpec.configure do |config|
    config.before(:each) { DataMapper.auto_migrate! }
    config.after(:all) do
      FileUtils.rm_rf(Dir["#{settings.root}/public/test_files"])
    end 
  end
end

谢谢!

【问题讨论】:

  • 我想我记得读过一个与 MRI 1.9.2 加载模块的方式有关的性能问题。我看看能不能把链接挖出来

标签: ruby unit-testing rspec sinatra spork


【解决方案1】:

ruby 1.9.2 在启动过程中需要文件的方式存在问题: http://rhnh.net/2011/05/28/speeding-up-rails-startup-time

1.9.3 对此 IIRC 进行了部分修复。

【讨论】:

    【解决方案2】:

    不是根据 rspec 自己的测试:https://gist.github.com/939865。它应该更快。你的堆栈中可能会比较慢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-25
      • 1970-01-01
      • 2011-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多