Why do my rspec tests run slower in Ruby 1.9.2 than 1.8.7?
Asked Answered
D

2

6

I'm using spork to test a Sinatra application and with Ruby 1.9.2 the tests run in about 3.5 seconds but in Ruby 1.8.7 they average 1.2 seconds. I did try Ruby 1.9.3 and even JRuby but they had some errors with the gems I'm using. Is there a way to bring Ruby 1.9.2's rspec performance up to 1.8.7's level?

My Gemfile:

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

thanks!

Discipline answered 7/12, 2011 at 22:5 Comment(1)
I think I remember reading about a performance problem linked to the way MRI 1.9.2 loaded modules. I'll see if I can dig out the linkFatherhood
F
2

There was a problem in the way ruby 1.9.2 require'd files during startup: http://rhnh.net/2011/05/28/speeding-up-rails-startup-time

1.9.3 has a partial fix for this IIRC.

Favor answered 8/12, 2011 at 0:34 Comment(0)
E
1

Not according to rspec's own test: https://gist.github.com/939865. It is supposed to be faster. It could be something slower in your stack.

Elyn answered 8/12, 2011 at 0:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.