下面是使用time rspec spec
和time bundle exec spec
在相當簡單的rails 3應用程序上進行的3次隨機運行。不使用捆綁器的速度一直更快,它使用的資源要少很多,6%vs 17%cpu。爲什麼'rspec spec'運行速度更快,使用資源比'bundle exec spec'更少
我確定它與處理依賴項的bundler有關,但我希望更好地理解此問題。我嘗試練習TDD,所以當然我會在一天中多次運行我的測試。如果使用bundle exec
將在速度和資源方面「花費」我然後我很想找到一種方法來避免使用bundle exec
。
我使用的鐵軌3.0.3,1.9.2紅寶石,RSpec的2.3,捆綁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
'bundle exec'的行爲就像一個沙箱,我會說,它是一個沙箱。想想你通過git獲得的寶石(因爲目前爲止尚未發佈的特殊補丁 - 這是在捆綁環境之外無法訪問的寶石)!所以bundler加載/準備您的孤立的寶石環境。如果你通過git使用gems,你真的需要使用bundle exec,否則會引發錯誤。 - 如果你只有rubygems託管的寶石,你可以離開「bundle exec」,因爲所有的寶石也可以在全球範圍內找到。 – asaaki 2011-06-03 12:26:46
Marginally OT,但如果您擔心測試運行時間並且經常運行測試,那麼您可能需要試用Spork。它基本上預先加載了您的測試環境,然後Rspec將其掛入,以便在每次測試之前不必旋轉它。 https://github.com/timcharper/spork – 2011-06-03 13:20:38
我在這裏有完全相反的問題。有誰知道爲什麼? http://stackoverflow.com/questions/7982589/rspec-and-bundle-exec – etang 2011-11-02 15:12:21