10

That time when I wowed all my colleagues with C++-code that executed over 2.5x faster than theirs, without changing one line of code.

I guess they didn't know what -O2 does (or that it exists, for that matter).

Comments
  • 5
    Most programmers don't know about compiler flags because the IDE makes it essentially invisible :( and even if theres an option for all the flags, god forbid someone googled it or explored their IDE when they don't have to -_-
  • 1
    Guess what, me neither, is it like a compiler argument?
  • 1
  • 3
    @Ranchu correct, you can specify an optimization-level (-O) with which the compiler tries to optimize for a specific goal (using less memory, faster code, smaller [code]size etc).
    Well, at least can with gcc and mvc, guess llvm does support it as well, not sure though.

    Higher levels can lead to bugs if you like to use aliasing or type punning though, so most devs are discouraged to even use them (according to the "if you don't know what it does, don't use it" addage).

    Only works if you have access to the compiler flags though. If you're in a project with a makefile managed by someone else, it gets quite exhausting to argue about compiler flags....

    And don't get me started about the volatile keyword. Even less devs know about it and when and how to use it. But I guess it's embedded specific so it stands to reason that it's not known by many :)
  • 0
    @Fakerlol does it work for most compilers or only certain ones?
  • 1
    @Ranchu Well I only ever used it with gcc, so I wouldn't know if it works with other compilers - at least with this specific flag.
    I'm pretty sure that all C/++ compilers worth their name have some sort of optimization routines built in, one just has to find out how to use them.

    Microsoft's has it, as you can change it through the properties of the project or with the corresponding flag (I think it was /O).

    Another tidbit: When using an IDE without a makefile, usually choosing Debug-Mode will compile with O0 and choosing Release-Mode will compile with O3. You can spot this in the compilers' output :)
  • 0
    @Fakerlol good to know, thanks
Add Comment