Will performance be better (quicker) if I manually compile the source for a software component for the actual machine that it will be used on, compared to if the source was compiled on another platform perhaps for many different architectures? I got some good results compiling source that I downloaded and I wonder whether this was due to compiling it instead of downloading a pre-compiled binary which is often the case with software updates.
2
In many (if not most) cases, yes. This because the compiler can produce native code optimized for that particular CPU and environment. The code is more “targeted”.
Compiling from sources gives you an advantage of setting the compiler flags the way you want for your specific platform. Downloading a package that has been compiled with the same exact settings as yours would offer no difference, but changing the settings from the defaults can get you big improvements.
For example, if the binaries offered for download were compiled for debugging (intentionally or by mistake), turning on more aggressive optimization will improve performance in nearly all situations. On the other hand, if the compiled code is optimized to the max, you would not see any difference.
1
This really depends on the two compilers and compiler flags used. Usually, the compiler and flag settings on your local machine are more appropriate to your particular machine if you have things configured correctly.
But, if, for instance, the pre-built binary happened to be built with a much better optimizing compiler (or a benchmark special designed with flags tuned for that particular piece of code and by luck appropriate for your system) compared to the compiler on your system, then it’s possible that whatever compiler is on your system might actually produce worse performance.