简体   繁体   中英

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.

The application targets .NET 4 and makes use of the task parallel library for about 60% of the loops and uses the BigInteger class.

I'm dealing with two ranges of numbers:

  • 0 to ulong.MaxValue (about 50% of the algo).
  • Very large integers with hundreds of thousands of digits (about 50% of the algo).

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.

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).

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?

The very best case you could see is 2x, but your actual improvement is likely to be significantly less than that.

On the other hand, 64-bit code takes up more memory (addresses are 64-bit). 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.

According to Amdahl's law , you'll see a maximum speed up by a factor of 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. 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.

x64 code and data takes slightly more space due to longer pointers, but provides significantly bigger address space. So depending on code you may get performance changes in any direction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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