On Apr 16, 2011, at 9:05 AM, Rodrigo Rosenfeld Rosas wrote: > Hi, I would like to figure out if it is possible for me to run my specs > faster than it currently is. > > Before start optimizing my specs for speed, I tried to figure out what was > the speed footprint of Rspec boot process itself for starting executing my > specs. So I took my simplest spec with a single fast example: > > time bundle exec rspec ./spec/models/decision_spec.rb > . > > Finished in 0.00794 seconds > 1 example, 0 failures > > real 0m19.202s > user 0m17.649s > sys 0m1.300s > > All my specs run in about 54s. That means Rspec itself is responsible for > about a third of the total time
Not really. If you want a sense of what RSpec is taking, do something like this: $ echo '1000.times do |n| describe n do it "is #{n}" do n.should eq(n) end end end' > example.rb $ time rspec example.rb .............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................. .......... Finished in 0.51265 seconds 1000 examples, 0 failures real 0m1.063s user 0m0.877s sys 0m0.131s So here, it took just over 1/2 a second to run 1000 examples and output a dot for each. This is admittedly slower than MiniTest/Spec $ echo 'require "minitest/autorun" > require "minitest/spec" > > 1000.times do |n| > describe "Spec#{n}" do > it "is #{n}" do > assert_equal(n,n) > end > end > end > ' > example.rb [david: rspec-core (master)]$ time ruby example.rb Loaded suite example Started .............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................. .......... Finished in 0.242546 seconds. 1000 tests, 1000 assertions, 0 failures, 0 errors, 0 skips Test run options: --seed 24068 real 0m0.571s user 0m0.537s sys 0m0.029s But if you have a couple of hundred examples that are taking 54 seconds, it is not because of RSpec. > ... Well, not exactly: > > time rails runner "puts 1" > 1 > > real 0m13.918s > user 0m12.805s > sys 0m0.940s > > This means I could not get more than 5s in the best case from trying to > optimize Rspec itself... Simple does not worth... > > Rails (3.0.7rc2) itself takes about 4s to boot up an empty application: > > rails new empty > cd empty > time rails runner "puts 1" > 1 > > real 0m4.000s > user 0m3.440s > sys 0m0.492s > > That means I can try to optimize my application boot time first, which can > reduce my specs running time up to 10 seconds... > > Then, I tried to give autotest a try in the hope it would skip the boot > process for the next spec executions. But it didn't. It is not that smart. It > just monitor file changes and call rspec on the possible affected specs... Check out spork. It loads the env once, and runs the suite in a fork each time you run it. > So, I would like to know if some of you know a good Ruby profiler that could > show me how much time each method takes on a tree view... For instance, I > enjoy very much the Javascript profiler that comes with Google Chrome > Developer Tool. > > I tried adding "-r profile" to .rspec, but the output is not that useful in > my opinion... And the "--profile" Rspec option will only show me the to 10 > slowest examples, but not what is the bottleneck, so I need to do that > manually... Also, it won't help me getting my Rails application to boot > faster... > > Does anyone here knows of a good tool for profiling or finding bottlenecks on > a Rails or Ruby application? > > Sorry if I took too long on my question... > > Cheers, Rodrigo. There is ruby-prof, and Rubnius has some profiling tools that look very interesting. HTH, David _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users