Running simulation code using GEANT4 (large Monte Carlo C++ simulation framework, lots of shared libraries). Compiled and linked GEANT and my app with gold linker and with standard BFD based linker. Looks like gold one is running a bit faster (1'47" vs 1'51"). Could someone shed a light what would be the reason for the difference? Ubuntu 15.04, 64bit, GCC 4.9.2. Run each test about 10 times, lowest time taken, no other activity, one terminal.
问题:
回答1:
Naturally, different linkers will produce different results, just like different compilers do. The result mostly depends on the optimization options that are enabled (and available) on each linker. Here is one possible reason for the differences you see, but there can be numerous others:
-fipa-icf
Perform Identical Code Folding for functions and read-only variables. The optimization reduces code size and may disturb unwind stacks by replacing a function by equivalent one with a different name. The optimization works more effectively with link time optimization enabled. Nevertheless the behavior is similar to Gold Linker ICF optimization, GCC ICF works on different levels and thus the optimizations are not same - there are equivalences that are found only by GCC and equivalences found only by Gold.
from: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
Last but not least: there are many environmental factors that can affect the runtime besides the actual binary content. E.g., cache thrashing can have a considerable effect on the execution time. Also, set of 10 executions is too small for statistical conclusions.
回答2:
As far as the statistics go, lowest time taken is not a valid measure. If you are really curious you need to compute the average time to completion for each program, then divide the difference in the averages by the standard deviation of the pooled sample.
Suppose both programs had the exact same average time to completion, but one always took the same amount of time, the other had huge variation. Picking the one with the single fastest completion would always choose the latter, even though the more consistent program is the one with better performance.