Performance of a C# application built on AnyCPU vs x64 platform on a 64 bit machine

Saurabh R S picture Saurabh R S · Jun 16, 2012 · Viewed 13.7k times · Source

I have to deploy a C# application on a 64 bit machine though there is a slight probability that it could also be deployed on a 32 bit machine. Should I build two separate executables targeting x86 and x64 platform or should I go for a single executable built targeting 'AnyCPU' platform (specified in the project property's Build option'. Would there be any performace difference between a C# assembly built targeting 'AnyCPU' is deployed on a 64 bit machine vs the same assembly built targeting specifically 'x64' platform ?

Answer

svick picture svick · Jun 16, 2012

No, there is no difference in performance between AnyCPU application running on a 64-bit Windows and an x64 application running on it. The only thing that flag changes are some flags in the header of the compiled assembly and the CLR uses it only to decide whether to use x86 or x64, nothing else

If you were asking whether there is a difference between x86 application running on a 64-bit Windows and an x64 (or AnyCPU), then the answer would be yes. The differences between the two are:

  • 64-bit obviously uses references that are twice as big as 32-bit, which means larger memory consumption, but it also means you can use more memory
  • 64-bit can use more registers that are available only in the 64-bit mode of CPUs
  • 64-bit JIT is different from 32-bit JIT, it has different set of optimizations: for example 64-bit JIT sometimes uses the tail call optimization even if you don't specifically request it using the tail. instruction (which for example C# never does)