ANSI C++ : Why such a vast difference in executable size on differnent platforms?

Started by
15 comments, last by random_thinker 18 years, 8 months ago
Maybe you should just try running the strip command on the final executable?
Advertisement
On my Gentoo Linux system, using the -Os flag:

reduced the program size from 240 to 210k

but increased random number generation time by by about 15%.

So on this OS the better flag is -O3 for performance purposes.

--random.
--random_thinkerAs Albert Einstein said: 'Imagination is more important than knowledge'. Of course, he also said: 'If I had only known, I would have been a locksmith'.
Thanks again Robo.

Here's the final result on the Mac:

Using the -O3 flag gives file size of 3.2 mb.

Using the -Os flag gives file size of 1.6 mb + improved performance over -O3.

Using the strip command on the final -Os file reduces size to a respectable 410 k with no loss of performance.

I really don't understand why the Mac linker would be so different, but maybe this is something to do with the BSD system basis.

Thanks for the help!

--random
--random_thinkerAs Albert Einstein said: 'Imagination is more important than knowledge'. Of course, he also said: 'If I had only known, I would have been a locksmith'.
Quote:Original post by random_thinker
So on this OS the better flag is -O3 for performance purposes.


Well, that depends on what you're actually doing as well. For this particular piece of code, then -Os is better than -O3, but for other code, it might be the other way around. After all, if it was better in general to use -Os, why would they even have a -O3? :)
The base code of my app has several random double [0,1) generators along with some processors for uniform, normal, exponential, lognormal and gamma variates. These use a lot of 'bit swapping' at their core and the -O3 flag is appropriate, and I can derive normal and exponential variates now as fast as the base standard library function rand() does with uniform variates only, with periods in excess of 2^33000, according to Marsaglia. As you noted, there are other applications which might not need an -O3 flag. I was surprized however, that on the Mac the -Os flag actually results in faster execution that the -O3 flag. This is not the case on the Gentoo Linux system. I haven't yet tried it on the WinXP/MinGW system yet.

In addition, I tried 'strip' vs 'strip -x' (as recommended by the Mac linker). The -x option didn't reduce the file size, rather it increased it from 410 to 450k. I have heard that there are some changes coming out from Apple including the phasing out of ranlib. Maybe ld is eventually going to be changed as well.

--random
--random_thinkerAs Albert Einstein said: 'Imagination is more important than knowledge'. Of course, he also said: 'If I had only known, I would have been a locksmith'.
Hi All,

Thought I'd post a summary of findings in this issue with WinXP included:

WinXP/MinGW g++ v3+

-O3 flag, strip, file size 820k, fast performance.
-Os flag, strip, file size 435k, ~20% slower than -03.

Gentoo Linux g++ v3+

-O3 flag, strip, file size 250k, fast performance.
-Os flag, no strip, file size 220k, ~20% slower than -O3.

MacOSX 10.2.8, g++ v3+

-O3 flag, no strip, file size 3.2mb, performance ~15% slower than -Os flag.
-Os flag, no strip, file size 1.7mb, fast performance.
-Os flag, strip. file size 410k, fast performance.

Performance is based upon generating a stream of 10,000,000 real numbers [0,1) and accumulating the statistics on these, including the first 4 moments, SQRT beta1, beta1 and beta2. This requires a lot of power multiplication and some square root work. Typically it requires about 0.34 secs on my AMD 2800XP machine. Simple raw random integer generation can be done at a rate of about 120 million per second with a period of than 2^33242.

For those who are interested, it seems that multi-platform compiling of the same ansi/stl compliant C++ code by the g++ compiler can be quite different, including the effect of various compiler flags. In this brief work, the WinXP and Gentoo Linux comparisons are on the same machine, whereas the MacOSX trial is on a G4 chip, explaining some of the executable variations, probably. If I were testing a Pentium-based machine, the results would surely be different again.

Thanks for all the excellent advice!
--random_thinkerAs Albert Einstein said: 'Imagination is more important than knowledge'. Of course, he also said: 'If I had only known, I would have been a locksmith'.
Oh, by the way, when I use the term 'real number' I mean double precision on a 32 bit chip.

--random
--random_thinkerAs Albert Einstein said: 'Imagination is more important than knowledge'. Of course, he also said: 'If I had only known, I would have been a locksmith'.

This topic is closed to new replies.

Advertisement