Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 449
kreek Avatar asked Dec 07 '11 22:12

kreek


2 Answers

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.

like image 136
Jamie Penney Avatar answered Nov 16 '22 20:11

Jamie Penney


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.

like image 25
DrChanimal Avatar answered Nov 16 '22 20:11

DrChanimal