12

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.

Niklas Rosencrantz
  • 8,008
  • 17
  • 56
  • 95
  • 2
    Compiling for compatibility with many architectures potentially eliminates certain optimizations that may be possible when compiling for a single architecture. – Robert Harvey Oct 04 '12 at 22:50
  • 1
    Aside from being more targeted (which will almost always be beneficial), you will probably *also* encounter large differences between compilers - different compilers support different optimisations, and sometimes performance bottlenecks may be optimised away by one, but not the other(s). – Daniel B Oct 05 '12 at 07:27

3 Answers3

9

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.

Sergey Kalinichenko
  • 17,393
  • 4
  • 57
  • 73
  • So my compiling effort might not have been in vain. I downloaded the source to mod_jk and compiled and it got very fast and I wonder if that was due to the manual compilation. Thank you for the answer. – Niklas Rosencrantz Oct 05 '12 at 05:15
8

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

epistemex
  • 543
  • 3
  • 6
2

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.

hotpaw2
  • 7,938
  • 4
  • 21
  • 47