为什么Jest

编程入门 行业动态 更新时间:2024-10-11 21:29:45
本文介绍了为什么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?

推荐答案

阅读链接页面和其他一些相关资源(例如此github问题)一些用户发现:

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

本文发布于:2023-10-26 17:35:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530854.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Jest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!