.Net Core 编译时间是否随 CPU 核心数量成比例减少?

发布于 2025-01-12 11:28:20 字数 1217 浏览 2 评论 0原文

我正在组装一台新电脑。我的主要用途是编写 C# .Net Core 项目。我想知道从 CPU 中添加的核心(例如英特尔第 12 代 i7-12700f(10 核心/20 线程))是否物有所值。

理想情况下,编译时间应几乎与内核数量呈线性关系,就像 Chromium 编译基准测试一样(特别是使用 Intel 第 12 代 CPU):

https://www.youtube.com/watch?v=xBDFCoGhZ4g&t=1021s

https://www.youtube.com/watch?v=2WklVah7ERo&t=561s

编辑1:

我在提出这个问题之前进行了搜索。我知道其他帖子,例如:

https://learn.microsoft.com/en-us/visualstudio/msbuild/using-multiple-processors-to-build-projects?view=vs-2022

Visual Studio 2012 是否利用所有可用的CPU 核心?

我知道.Net 编译器可以利用多核的优势。

我的问题具体是关于 C#/.Net 编译时间如何随着 CPU 核心数量的变化而变化(在一代 CPU 中,例如英特尔第 12 代),就像 C/C++/Chromium 编译基准测试一样。我希望这仍然是一个合法的问题。

编辑2:

这个问题是关于单个中型项目的编译时间。不编译肯定会随核心扩展的多个项目。

I'm building a new PC. My main usage will be coding C# .Net Core projects. I wonder whether the added cores from CPU such as Intel 12th gen i7-12700f (10 cores/20 threads) would be worth the money.

Ideally, the compiling time should improve almost linearly with the number of cores as in case with the Chromium compiling benchmarks (specifically, with the Intel 12th gen CPUs):

https://www.youtube.com/watch?v=xBDFCoGhZ4g&t=1021s

https://www.youtube.com/watch?v=2WklVah7ERo&t=561s

Edit 1:

I did search before making this quesstion. I'm aware of the other posts such as:

https://learn.microsoft.com/en-us/visualstudio/msbuild/using-multiple-processors-to-build-projects?view=vs-2022

Does Visual Studio 2012 utilize all available CPU cores?

I know .Net compiler can take advantages of multi-core.

My question is specifically about how C#/.Net compiling time would scale with the number of CPU cores (within one CPU generation such as Intel 12th gen) as in case of C/C++/Chromium compiling benchmarks. I hope this is still a legit question.

Edit 2:

This question about the compiling time of one single medium-size project. Not compiling multiple projects which certainly scales with cores.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉睡月亮 2025-01-19 11:28:20

这可能是题外话,但早期版本的 .net 中存在其他类似问题,类似于:Visual Studio 是否这样做2012 利用所有可用的 CPU 内核?

首先,您要确保启用多处理器编译:启用并行构建
启用并行Builds

然后,您需要确保运行的是 Visual Studio 2022,以便可以利用管道中的所有 64 位。

然后,要确定是否值得额外花费 $$$,请使用 xkcd 中的此图表: Is It Worth the Time?

这实际上是一篇严肃的文章。什么样的改进措施才值得这样做?
如果您每天编译 50 次,而改进仅 1 秒,那么值得额外花费 1 个计费日。该图表表明,在 5 年内,这些秒数将总计增加一整天的额外计费工作。

让我们把这个价格定为 200 美元。

现在如果你像我一样,一天会编译50多次,每次编译周期可能长达60秒。即使操作系统和 Spotify 的其余部分以及您的网络浏览器可以在您等待构建时继续运行,也可以节省额外的内核,这意味着我们将轻松获得至少 1 秒的时间(在 VS 编译之上)。

现在我们节省了 800 美元。即使在我们进行基准测试之前,只要您对 5 年投资感到满意,我们就可以轻松地证明额外花费 800 美元是合理的。

我是否对这些最新的 CPU 与 VS 2022 进行了基准测试,没有。但如果我这样做了,我会很快说服自己购买一个新的开发设备;)如果您执行频繁的编译,那么对 CPU、RAM、HDD 和通用总线速度的所有改进都会有所帮助,但最常见的情况是HDD是性能的瓶颈。经过所有编译后,文件需要写入某个地方,因此,如果您正在考虑范围的顶部但预算有限,我会投资最好的 HDD 和良好的 CPU,而不是相反。

this is probably off-topic, but other questions like this exist for earlier versions of .net, similar to this: Does Visual Studio 2012 utilize all available CPU cores?

First you want to make sure that multi-processor compilation is enabled: Enabling Parallel Builds
Enabling Parallel Builds

Then you want to make sure you are running Visual Studio 2022 so you can take advantage of all 64 bits in the pipeline.

Then to determine if it is worth the extra $$$, use this chart from xkcd: Is It Worth the Time?

This is actually a serious post. What improvement measure would make it worth it?
If you care compiling 50 times a day, and the improvement was only 1 second, then it is worth spending 1 billable day worth extra. This chart states that over 5 years, those seconds will add up to 1 entire day of additional billable work.

Lets just low ball that at $200.

Now if you are like me, you will be compiling more than 50 times in a day, and each compilation cycle can be up to 60 seconds. The saving of having additional cores even so the rest of the OS and Spotify and your web browsers can keep churning away while you wait for builds, means that we will easily get at least 1 second, on top of the VS compilation.

So now we have a saving of $800. Even before we benchmark it, we can easily justify spending $800 extra, as long as you are happy with the 5 year investment.

Have I benchmarked these latest CPUs against VS 2022, no. But if I did that I'd very quickly talk myself into buying a new dev rig ;) If you are performing frequent compilations then all improvements to CPU, RAM, HDD and general bus speed will help, but it is most common to find that the HDD is the bottleneck for performance. After all that compilation the files need to be written somewhere, so if you are looking at the top of the range but are on a budget, I would invest in the best HDD and a good CPU, rather than the other way around.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文