Skip to content

Instantly share code, notes, and snippets.

@ngauthier
Created February 14, 2012 16:50
Show Gist options
  • Select an option

  • Save ngauthier/1828061 to your computer and use it in GitHub Desktop.

Select an option

Save ngauthier/1828061 to your computer and use it in GitHub Desktop.
333% Test Speedup

333% Test Speedup

  1. Normal Rails setup: 30 seconds for rake test
  2. Using 1.9.3-falcon: 22 seconds
  3. Using merged task w/ db reset: 16 seconds
  4. Using merged task w/o db reset: 12 seconds
  5. Using raw ruby execution: 9 seconds

You can run rake test:fast:db to get a merged run that resets your db. However, if you have clean tests that don't pollute the db between runs, you can just run rake test:fast and it will omit db:reset. This means your sequence numbers (under PostgreSQL, at least) may keep increasing, but if you tests against those I have other words for you.

xoxo <3 <3 <3 @ngauthier

# Usage: rtest.sh test/**/*_test.rb
ruby -Ilib:test `bundle list rake`/lib/rake/rake_test_loader.rb $*
namespace :test do
desc 'Run tests quickly by merging all types and not resetting db'
Rake::TestTask.new('fast') do |t|
t.libs << 'test'
t.pattern = "test/**/*_test.rb"
end
namespace :fast do
desc 'Run tests quickly, but also reset db'
task :db => ['db:test:prepare', 'test:fast']
end
end
@ngauthier
Copy link
Copy Markdown
Author

Awesome, yeah that was what I was going to try next. Maybe turn that into a bash alias or something. If you enable bash's globstar you can just do ruby -Itest -Ilib test/**/*_test.rb.

@ngauthier
Copy link
Copy Markdown
Author

Updated with rtest.sh which is even faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment