64-bit Performance Advantages

2019-01-12 02:51发布

问题:

What is the source of the performance advantage 64-bit applications have over 32-bit applications? I'm assuming there is a performance advantage because programs like WinRAR advertise it.

Also, can we get these performance advantages simply by switching to a 64-bit compiler, or are there any changes in code that need to be made?

Answers related to both, unmanaged and managed code, are welcome.

回答1:

In order to take advantage of the 64 bit architecture of the latest CPU's you have to:

  • use a 64 bit CPU and OS
  • develop specifically for 64 bits using a 64 bit api - the implementation has to go all the way down to the most basic code working with the CPU registers (normally written in assembler) to take advantage of the extra registers.
  • develop an application that will really benefit from the extra registers - WinRAR is an application that will take full advantage of the extra registers because it involves a lot of calculus with complex algorithms. If you instead write an application with very simple algorithms, it will not require extra register address space and it will not work faster on 64 bit
  • take also into consideration that when you use a CPU register even if you don't use the the whole address space for a value, it will still take up as much space ( = 64bits).. therefore writing a small application in 64 bit aiming for getting a optimized code will just not work.. that app will take up twice the RAM than if it would be developed under 32 bit and it may be even slower. Programming in 64 bit makes sense for applications using heavy algorithms or that need to allocate huge pieces of memory (4Gb is the limit for a 32bit app).


回答2:

The x64 architecture doubles the number of general purpose registers available in the x86 architecture, so that compilers are able to keep more data in (very fast) CPU registers rather than in (relatively slow) RAM.



回答3:

When did they stop lying in ads? Did I miss something? ;-)

The major performance advantage is that in 64bit systems, you can allocate more than 4GB of RAM (actually on most systems that's more 2GB) without swapping. That's a huge speed advantage if you need it.

So 64bit gives an advantage if you have applications that need lots of RAM (image/video/audio processing, world/universe simulations).

On top of that, the 64bit CPUs also have commands that operate on 64bit data types (so you don't need to emulate those with 32bit types). That's also an advantage but it's a) not that big because you the algorithms need to use those types and most don't b) they are still slower then 32bit types (but faster than the emulation).

To give you an idea, here is an old joke from a supercomputer guy: "It takes one day to load the data from disks, then the program takes five minutes to process the data and then we need another day to save the result to disk". Reading data from RAM is between 1000 and 1000000 times faster than an access to disk.

So all in all, for the average user, a 64bit system has little to no advantage.



回答4:

My understanding is that in most circumstances, there is no performance gain as such, apart from the ability to use more memory. (Although it might give higher performance if you're working with 64-bit data types a lot, for example).



回答5:

Some great answers here.

As was said, you can access unlimited RAM, which will help performance if you need it.

I would humbly add that if you don't need it, but use it anyway, it will hurt performance.

Never lose sight of one of the oldest laws of science:

Nature Abhors a Vacuum