curaga
Group: Members
Posts: 2163
Joined: Feb. 2007 |
|
Posted: Dec. 15 2007,10:54 |
|
I thought I'd gather some tips here, along with explanations.
Optimization levels: -O3 Highest -Os Like O2, but also optimizes for size. This is a very good option; smaller programs take less ram too. The linux kernel is a good example: the recent 2.6 kernels have an experimental option to turn -Os on. To me it resulted in a kernel that took an entire mb less ram! And because this was for a 16mb machine, it really showed: free ram right after boot increased from 12mb to 13mb. (including 3 gettys running) -O2 The usual level -O Smallest optimization -O0 That's O zero. No optimization at all.
Optimization for certain processor: Tests have shown this (with -O3) makes programs about 15% faster if run on the cpu optimized for. The difference is biggest with i586 chips, because of their unique design, they get about 20% more speed. -march=pentium2 Sets minimum processor to pentium2. Also optimizes for it. -mcpu=pentium2 Optimizes for P2, but doesn't touch the minimum; ie this is still runnable on i386.
All the above go into CFLAGS/CXXFLAGS. Everything below goes into LDFLAGS.
-Wl,-rpath -Wl,/opt/prog/lib A linker option to add /opt/prog/lib to the runtime library search path. This is useful for not needing to create a wrapper script to run the app, that usually sets LD_LIBRARY_PATH to that dir so the app finds it's libraries.
-Wl,-as-needed This is a really interesting option. Let's say we have a gtk1 app that only uses libgdk. But gtk-config --libs (that the makefile uses) causes it to link with all the gtk1 libs, causing slow start because all these libraries are loaded into memory. But if you give this flag, the program will only get linked with the libraries it uses; resulting in a faster startup, and a cleaner looking ldd output. *Warning* this requires binutils 2.17.
-s Strips the results during linking, saving you some time.
PS: for compiling speed, if you ever compile GCC yourself, be sure to do it with profiling optimization. It speeds up C compiling up to 9%.
-------------- There's no such thing as life. Those mean little jocks invented it ;) - Windows is not a virus. A virus does something!
|