Following a thread on the Clang mailing list, I did a quick analysis of the optimization flags used to build C or C++ code.
I used a rebuild result from last mid July of all Debian native packages (meaning that I don't have the log of full Java, Python or other packages without native code) and wrote a small script to count all their occurrences.
By default, deb packages uses the command "dpkg-buildflags --get CFLAGS" which will set the optimization level to -O2. However, many packages and upstream build systems do not respect such flags.
On 10320 binary-only packages (in total, Debian has around 19000), the results are the following:
Optimization level | Number of occurrences | Number of packages |
-O | 35597 | 269 |
-Os | 30849 | 145 |
-O0 | 13993 | 294 |
-O1 | 25494 | 809 |
-O2 | 995803 | 7685 |
-O3 | 106048 | 531 |
-O4 | 1402 | 16 |
-O5 | | |
-O6 | 6935 | 49 |
Since a graphic talks more than numbers (note that the Y axis is logarithmic):
Disclaimer:
Some packages are using several optimization flags during the same build.
Some packages are not showing the full command line (see jessie release goal: verbose build logs)
The results might be approximate since I am basically grepping "-OX " on the log files.