Parvinder Singh
Parvinder Singh

Reputation: 1757

Which compilation flag should I use -> Os or O2?

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.

Upvotes: 1

Views: 1121

Answers (2)

poige
poige

Reputation: 1853

-Os is preferable. Not only are there RAM limits, but the CPU's cache size is limited as well, so -Os code can be faster executed in despite of using less optimization techniques.

Upvotes: 1

P.P
P.P

Reputation: 121387

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.

Upvotes: 2

Related Questions