为什么Jest --runInBand可以加快测试速度? [英] Why does Jest --runInBand speed up tests?

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

问题描述

我了解到

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?

推荐答案

阅读链接页面和其他一些相关资源(例如

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)

我们可以看到,即使这些用户的资源有限,这些用户的计算机性能也得到了改善.如果我们从 docs 中读取--runInBand标志的作用,说:

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天全站免登陆