Any CPU or x64?


I searched for compilation on Any CPU and x64, but found nothing regarding performance and file size. Is there a difference between these two in this question when the machine is x64?

Website using C # in VS 2017, MVC 3, .NET Framework 4.7

asked by anonymous 30.08.2017 / 17:06

1 answer


In the .NET Framework it makes no difference in terms of executable size because the generated code is a CIL and not a native code, what goes is a bytecode which in execution will generate a native code through the JITter .

What changes when you choose a CPU or leave it to any is where the code can run, it's to create the right dependencies.

If you choose x64 you will not be able to run on an x86 machine and if you choose x86 it will run in compatibility mode on x64.

If you choose Any CPU runtime will generate the native code according to the architecture you are running.

.NET assemblies can not merge architectures, so if you choose one of them, you can only run together with assemblies from the same architecture.

The native x64 code will be slightly larger because all addressing will occupy 8 bytes instead of 4 bytes which is the size of x86. There are other differences of instructions that can make the native code in memory get larger or smaller.

In general x64 runs faster, but not always. But you do not have to choose, leave Any CPU.

In some cases choosing x86 may give you some advantage, just testing to find out.

The CLR chooses the best way when it is in Any CPU, so it is almost always the best choice. In general, you only have to choose the architecture if you are going to run an unmanaged code together for one specifically.

Article in more detail .

30.08.2017 / 17:55