I just noticed an interesting difference between Perl's ExtUtils::MakeMaker and Ruby's mkmf - Perl defaults to -O while Ruby defaults to -O2 (the optimization level).
I'm not sure how much of a difference this *really* makes - I haven't done any serious benchmarks, though I saw no difference between -O2 vs -O3 when I tested a Ruby module.
Is there any reason NOT to put 'OPTIMIZE => "-O2"' for extensions in your Makefile.PL? All the gcc manual says is that it might make debugging more difficult and use more memory during the build phase. Not much of an issue for the majority of extensions out there, I don't think.
They're mostly the same
Elian on 2003-03-31T21:51:36
-O is "default optimization level", which may be -O1, -O2, or -O3, depending on how GCC's set up.
Also, optimizing interpreters is
ery non-trivial, and they don't optimize nearly the same way as other, more straightforward, programs do, so the lack of noticeable difference isn't that surprising.
Re:They're mostly the same
djberg96 on 2003-04-01T17:19:13
I'm confused then (bear with me - it happens often). According to the gcc docs, "-O" is its own option, separate from "-O0", which is the (factory) default setting. But then, I can't seem to figure out how to tell what the default optimization level is in the first place (assuming it's been changed from -O0).
Re:They're mostly the same
Elian on 2003-04-01T17:43:55
You can check the installed man page for gcc and hope it's up to date. For OS X, -O and -O1 are the same, and it looks the same for my linux box, though whether that's true or not is something else entirely.
Which optimizations -O turns on for various optimization levels is potentially build and system dependent, just to add some fun into the mix. And, of course, GCC's optimizer gets slowly better over time, so even if the settings are identical you may get different runtimes depending on the version of GCC (or any C compiler, for that matter) that you use.
Maybe
Dom2 on 2003-03-31T22:21:19
It's probably all right most of the time. Most likely on well tested platforms like x86 Linux. But by the time you get on to the platforms where gcc is less well tested at all of it's optimsations, you can come across subtle bugs. At least, that's the impressionI get from the very conservative FreeBSD guys. They will not endorse compiling world or kernel with -O2, only -O.
Ultimately, it's really a user choice though, and not something that should be embedded in a Makefile. If you want all your CPAN downloads compiled with -O2, then configure CPAN to pass the right args to Makefile.PL. Problem solved.
-Dom
Its not MakeMaker, its you.
schwern on 2003-04-02T01:08:35
MakeMaker is just following whatever is in your Config.pm which is whatever you decided the optimization level should be when you configured and installed Perl. If you took the default,
then it comes from whatever configuration hints are available for your OS. Most these days
use -O2 or -O3. Some, like OS X, choose -Os by default. Others (SCO, IRIX, AU/X) use -O to
play it safe.
And if you installed Perl from a vendor (Debian, Redhat, Sun, etc...) they could have changed the default, too.
Here's my stock perl delivered from Apple.
$ perl -MConfig -wle 'print $Config{optimize}'
-Os
The 5.8.0 I compiled myself and overrode the default optimization choice:
$ perl5.8.0 -MConfig -wle 'print $Config{optimize}'
-O3 -g
Here's the bleadperl I just compiled with the default config:
$ DYLD_LIBRARY_PATH=.
./perl -Ilib -MConfig -wle 'print $Config{optimize}'
-Os
Finally, the stock Debian perl:
$ perl -MConfig -wle 'print $Config{optimize}'
-O2
If you want to override this when building modules, just do this:
perl Makefile.PL OPTIMIZE='-Os -g'
and then make normally.