Below are 3 random runs using time rspec spec
vs time bundle exec spec
on a fairly simple rails 3 app. Not using bundler is consistently faster AND it uses a lot less resources, 6% vs 17% cpu.
I'm sure it has something to do with bundler handling the dependencies but I'd like to understand this problem better. I try to practice TDD so of course I run my tests many times throughout the day. If using bundle exec
is going to "cost" me in terms of speed and resources then I'm tempted to find a way to avoid the use of bundle exec
.
I am using rails 3.0.3, ruby 1.9.2, rspec 2.3, bundler 1.0.10
rspec spec 0.47s user 0.13s system 6% cpu 8.758 total
rspec spec 0.47s user 0.12s system 6% cpu 8.521 total
rspec spec 0.46s user 0.12s system 6% cpu 8.528 total
bundle exec rspec spec 1.35s user 0.30s system 17% cpu 9.293 total
bundle exec rspec spec 1.39s user 0.31s system 17% cpu 9.749 total
bundle exec rspec spec 1.37s user 0.30s system 17% cpu 9.490 total
I speculate that bundler has to dynamically parse all the gems in your gemfile before commencing the command.
Try
versus
on a simple rails 3 project on this machine, I get 25 and 92 gems respectively.
Similarly try the same with a simple "ls" command, and you still see the speed difference.
This doesn't quite answer your question directly as far as why one is slower. But I wanted to at least say for anyone who finds this later that it's generally only a coincidence that running executables without using
bundle exec
works. To quote the Bundler documentation: