Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
1  
Compiling for compatibility with many architectures potentially eliminates certain optimizations that may be possible when compiling for a single architecture. –  Robert Harvey Oct 4 '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 5 '12 at 7:27

3 Answers 3

up vote 5 down vote accepted

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

share|improve this answer

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.

share|improve this answer
    
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. –  909 Niklas Oct 5 '12 at 5:15

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.