为什么“ rspec规范”比“ bundle exec规范”运行得更快并且使用更少的资源 [英] Why does 'rspec spec' run faster and use less resources than 'bundle exec spec'

查看:61
本文介绍了为什么“ rspec规范”比“ bundle exec规范”运行得更快并且使用更少的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是在相当简单的Rails 3应用程序上使用 time rspec spec time bundle exec spec 进行的3次随机运行。不使用捆绑软件的速度始终更快,并且它使用的资源要少得多,CPU占用率分别为6%和17%。

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.

我确定它与捆绑器处理依赖项有关但我想更好地了解这个问题。我尝试练习TDD,所以我当然会在一整天内进行多次测试。如果使用 bundle exec 会在速度和资源上浪费我,那么我很想找到一种避免使用的方法。捆绑执行器

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.

我正在使用Rails 3.0.3,ruby 1.9.2,rspec 2.3,bundler 1.0.10

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


推荐答案

就为什么要慢一些,这并不能直接 answer 您的问题。但我想对后来发现这一点的人至少说,运行不使用 bundle exec 的可执行文件通常只是一个巧合。引用Bundler文档:

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:


在某些情况下,如果
运行不带软件包exec的可执行文件
可能会起作用可执行文件恰好安装在
您的系统中,并且不会引入任何与您的软件包冲突的
gem。

In some cases, running executables without bundle exec may work, if the executable happens to be installed in your system and does not pull in any gems that conflict with your bundle.

但是,这是不可靠的,是相当痛苦的
来源。即使
看起来可以工作,将来也可能不会
或在其他
机器上工作。

However, this is unreliable and is the source of considerable pain. Even if it looks like it works, it may not work in the future or on another machine.

这篇关于为什么“ rspec规范”比“ bundle exec规范”运行得更快并且使用更少的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆