I\'m distributing a C++ program with a makefile for the Unix version, and I\'m wondering what compiler options I should use to get the fastest possible code (it falls into t
I would try profile guided optimization:
-fprofile-generate
Enable options usually used for instrumenting application to produce profile useful for later recompilation with profile feedback based optimization. You must use-fprofile-generate
both when compiling and when linking your program. The following options are enabled:-fprofile-arcs
,-fprofile-values
,-fvpt
.
You should also give the compiler hints about the architecture on which the program will run.
For example if it will only run on a server and you can compile it on the same machine as the server, you can just use -march=native
.
Otherwise you need to determine which features your users will all have and pass the corresponding parameter to GCC.
(Apparently you're targeting 64-bit, so GCC will probably already include more optimizations than for generic x86.)