Friday, June 17, 2011

Speed test: rake vs. rspec spec, rake cucumber vs cucumber

I timed different rspec commands to see which ran faster.

These tests were done on a really old machine so the times would be drawn out.
Newer machines execute far quicker with negligible difference.

(Precondition: all tests run with regard to the same code.)

Test 1: rake spec:controllers vs. rspec spec/controllers
Results:
rake spec:controllers --> 23 seconds
rspec spec/controllers --> 15 seconds

Test 2: rake spec:models vs. rspec spec/models
Results:
rake spec:models --> 34 seconds
rspec spec/models --> 16 seconds

Test 3: rake spec:views vs. rspec spec/views
Results:
rake spec:views --> 20 seconds
rspec spec/views --> 11 seconds

Test 4: rake spec vs. rspec spec
Results:
rake spec --> 20 seconds
rspec spec --> 11 seconds

Conclusion: It is faster to use "rspec spec/..." than the broader "rake spec" command.

This makes sense because the rake command has to invoke the Rakefile first, and from what I've seen online, "rake spec" and "rake cucumber" also invoke "rake db:test:prepare" behind the scenes first - a necessary command to restore the test database from scratch if you blew away the old one.

Here's one more test I did - this time, with cucumber:

Test 5: cucumber vs. rake cucumber
Results:
rake cucumber --> 30 seconds
cucumber --> 21 seconds

Yep.

1 comment:

  1. Actually, the rake tasks boot the rails environment to load the rake tasks, and then the test runner *spawns a new process* to run the tests, which loads the environment again.

    The difference in time you're seeing is the extra time while rails boots (unnecessarily).

    ReplyDelete

Please be considerate in what you say.