简体   繁体   English

.NET(C#)中的64位应用程序可提高性能

[英]Performance benefit from 64 Bit applications in .NET (C#)

I'm porting a complex algorithm from 32 Bit to 64 Bit that takes about 5 hours to compute on my Core i5 machine with 8GB RAM running Windows 7 64 Bit. 我正在将复杂的算法从32位移植到64位,这需要大约5个小时才能在运行Windows 7 64位的8GB RAM的Core i5机器上进行计算。

The application targets .NET 4 and makes use of the task parallel library for about 60% of the loops and uses the BigInteger class. 该应用程序以.NET 4为目标,并使用任务并行库处理大约60%的循环,并使用BigInteger类。

I'm dealing with two ranges of numbers: 我正在处理两个数字范围:

  • 0 to ulong.MaxValue (about 50% of the algo). ulong.MaxValue为0(大约是算法的50%)。
  • Very large integers with hundreds of thousands of digits (about 50% of the algo). 具有数十万个数字的非常大的整数(约占算法的50%)。

The operations performed on these numbers include addition, subtraction multiplication, division, logarithm and power. 对这些数字执行的运算包括加法,减法乘法,除法,对数和幂。

Once ported to 64 Bit, I will be able to profile and time the code to see performance increase but I wanted to know if I can estimate it through calculation. 移植到64位后,我将能够对代码进行分析和计时,以提高性能,但我想知道是否可以通过计算来估计它。

If so, please recommend some articles that explain the same. 如果是这样,请推荐一些解释相同的文章。

I'm not sure what you are trying to port (unless there's native code in the mix). 我不确定您要移植的内容(除非混合使用本机代码)。 If you already have a 64-bit machine, just ensure you target a 64-bit runtime (the default AnyCPU will do that). 如果您已经拥有64位计算机,则只需确保以64位运行时为目标即可(默认的AnyCPU将执行此操作)。

The specific performance improvement will depend on the nature of your algorithms. 具体的性能改进将取决于算法的性质。 For one measurement that may give you an order of magnitude see 对于可能给您一个数量级的测量,请参见

Why is this faster on 64 bit than 32 bit? 为什么在64位上比32位上更快?

The very best case you could see is 2x, but your actual improvement is likely to be significantly less than that. 您可能会看到的最好的情况是2倍,但实际改进可能会大大小于2倍。

On the other hand, 64-bit code takes up more memory (addresses are 64-bit). 另一方面,64位代码占用更多的内存(地址是64位)。 If moving to 64-bit happens to force you to start swapping due to the increased memory needed for the JITed code, overall performance may decrease. 如果由于JITed代码所需的内存增加而碰巧迁移到64位迫使您开始交换,则总体性能可能会下降。

According to Amdahl's law , you'll see a maximum speed up by a factor of 1.33. 根据阿姆达尔定律 ,您将看到最大速度提高了1.33倍。 There are applications (eg. bitboard chess engines) such that going from 32 bits to 64 bits will almost exactly double performance, but that is when almost all the data is 64 bit and is manipulated using bitwise operations. 有一些应用程序(例如,位板国际象棋引擎),从32位变为64位几乎可以使性能提高一倍,但这就是当几乎所有数据都是64位并使用按位运算进行操作时。 It's hard to say without specific details, but in your case it will probably be less than the predicted factor. 没有特定的细节很难说,但是在您的情况下,它可能会小于预测的因子。

I'm afraid try and measure is the only reasonable approach. 恐怕尝试测量是唯一合理的方法。 Especially since you are "porting... 32 to 64 bit" which assumes at least partial code rewrite it would be very hard for one to give any guidance on performance numbers. 特别是由于您“移植... 32到64位”(假设至少要重写部分代码),因此很难就性能数字给出任何指导。

x64 code and data takes slightly more space due to longer pointers, but provides significantly bigger address space. 由于指针更长,x64代码和数据占用的空间略多,但提供的地址空间则大得多。 So depending on code you may get performance changes in any direction. 因此,根据代码的不同,您可能会在任何方向上发生性能变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM