Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

djberg96 (2603)

  (email not shown publicly)

Journal of djberg96 (2603)

Monday March 31, 2003
04:04 PM

Optimization flags

[ #11347 ]
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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • -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.
    • 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).
      • 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
  • 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 d

  • MakeMaker is just following whatever is in your 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 p