Take the 2-minute tour ×

I'm currently working on an embedded device application (in C). What optimization flag should I use for compiling that application keeping in mind that it only has 96 MB of RAM.

Also, please note that in this application, I'm basically pre-processing the JPEG image. So which optimization flag should I use ?

Also, does stripping this app will have any effect on efficiency and speed ?

The OS on which I'm running this app is Linux 2.6.37.

share|improve this question
Is the app so bit that it may not fit into 96MB? What's stripping? Removing debug symbols/info from the executable or something else? –  Alexey Frunze Oct 8 '12 at 9:09
Please don't choose the optimization flag based on somebody's opinion. Benchmark them yourself, and see if the trade-off is worth it. Anyway, based on the amount of information you have shared, its not possible for anyone to make a meaningful suggestion. –  ArjunShankar Oct 8 '12 at 9:18
Also, read this. –  ArjunShankar Oct 8 '12 at 9:21
add comment

2 Answers

up vote 2 down vote accepted

-Os is preferable — there's not only RAM limit but CPU's caches size is limited as well, so actually -Os code can be faster executed in despite of using less optimization techniques.

share|improve this answer
You are right about the fact that in some cases -Os is faster. But I really think the best choice of flag can only be made after benchmarking. "-Os is preferable" - I would say this is guesswork, or at best, a rule-of-thumb which may or may not always be a win. –  ArjunShankar Oct 8 '12 at 9:24
@ArjunShankar, well, "preferable" for those circumstances OPs are described. Honestly I don't expect to see valuable difference in run time between those 2 optimizations anyway. And code size difference is heavily dependent on overall executable .CODE section size. So, it's just a matter of what is in general seems to be appropriate for embedded. –  poige Oct 8 '12 at 9:35
add comment

Generally optimization increases the binary size. Besides what effect this will have on speed is not predictable at all depending on the data set that you have. The only way is to benchmark the application with different set of flags, not just -O2 or -O3 but with other possible flags which you think may improve the performance of the application as I believe you'd have information on what the program does and how it might behave for different inputs.

The performance is dependent on the nature of the application, hence I don't think anyone can give you a convincing answer as to which flags can give you better performance.

Look at the GCC optimization flags and analyze your algorithm so as to find suitable flags and then decide which ones to use.

share|improve this answer
add comment

Your Answer


