Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I speed up Ruby/Rake task

Tags:

ruby

rake

sinatra

rake --tasks takes about 18s to run. This is just the time it takes to load all the tasks, as a result any task I define will take at least this amount of time to run :

$time rake --tasks
rake db:clean           # Cleaning up database
rake passenger:restart  # Restart Application
rake spec               # Run specs

real    0m18.816s
user    0m7.306s
sys 0m5.665s

My Rakefile :

$: << "."
require "rubygems"
require "rspec/core/rake_task"

desc "Run those specs"
task :spec do
  RSpec::Core::RakeTask.new(:spec) do |t|
    t.rspec_opts = %w{--colour --format progress}
    t.pattern = 'spec/*_spec.rb'
  end
end

task :default  => :spec

Any idea why rake takes to much times ? Thanks

like image 871
Laughingman Avatar asked Dec 17 '11 14:12

Laughingman


2 Answers

Try spring

Command line will look like:

spring rake -T

It will take more time running the first time, but subsequent runs will be very fast.

like image 158
Grimmo Avatar answered Sep 19 '22 20:09

Grimmo


This solution worked for me: Faster rake tasks in Rails.

I had to do a little variation where I created a lib/tasks/no_rails directory and put all the Rake files which do not need Rails in there and loaded only those using the above method.

like image 27
Pratik Khadloya Avatar answered Sep 20 '22 20:09

Pratik Khadloya