为什么 Jest --runInBand 会加速测试? [英] Why does Jest --runInBand speed up tests?

查看:12
本文介绍了为什么 Jest --runInBand 会加速测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到 --runInBand 标志将 CI 服务器上的 Jest 测试持续时间加快了 50%.除了它让测试在同一线程中按顺序运行之外,我无法真正在网上找到关于该标志的作用的解释.

I read that the --runInBand flag speeds up Jest test duration by 50% on CI servers. I can't really find an explanation online on what that flag does except that it lets tests run in the same thread and sequentially.

为什么在同一个线程中运行测试并顺序使它更快?直观地说,这不应该让它变慢吗?

Why does running the test in the same thread and sequentially make it faster? Intuitively, shouldn't that make it slower?

推荐答案

阅读您的链接页面和其他一些相关资源(例如 this github issue) 一些用户发现:

Reading your linked page and some other related sources (like this github issue) some users have found that:

...使用 --runInBand 有助于在资源有限的环境中使用.

...using the --runInBand helps in an environment with limited resources.

... --runInBand 将我们的测试从 > 1.5 小时(实际上我不知道多长时间,因为 Jenkins 在 1.5 小时超时)到大约 4 分钟.(注意:我们的构建服务器确实资源匮乏)

... --runInBand took our tests from >1.5 hours (actually I don't know how long because Jenkins timed out at 1.5 hours) to around 4 minutes. (Note: we have really poor resources for our build server)

正如我们所见,这些用户在他们的机器上的性能有所提高,即使他们的资源有限.如果我们从 --runInBand 标志的作用>docs 它说:

As we can see, those users had improvements in their performances on their machines even though they had limited resources on them. If we read what does the --runInBand flag does from the docs it says:

别名:-i.在当前进程中连续运行所有测试,而不是创建运行测试的子进程工作池.这对调试很有用.

Alias: -i. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging.

因此,考虑到这些评论和文档,我相信性能的提高是由于现在进程在单个线程中运行的事实.这极大地帮助了资源有限的计算机,因为它不必花费内存和时间来处理和处理线程池中的多个线程,而对于其有限的资源来说,这项任务可能会被证明过于昂贵.

Therefore, taking into consideration these comments and the docs, I believe the improvement in performance is due to the fact that now the process runs in a single thread. This greatly helps a limited-resource-computer because it does not have to spend memory and time dealing and handling multiple threads in a thread pool, a task that could prove to be too expensive for its limited resources.

但是,我相信只有在您使用的机器资源有限的情况下才会出现这种情况.如果您使用更强大"的机器(即:多个内核、体面的 RAM、SSD 等),使用多线程可能会比运行单个线程更好.

However, I believe this is the case only if the machine you are using also has limited resources. If you used a more "powerful" machine (i.e.: several cores, decent RAM, SSD, etc.) using multiple threads probably will be better than running a single one.

这篇关于为什么 Jest --runInBand 会加速测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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