Search code examples
coptimizationcodeblocksgnu

GNU GCC Intel i5 optimization settings?


I have a Microsoft Surface Pro (5th Generation) with the i5 processor and use the GNU GCC Compiler. Now I want to use optimization settings for this compiler and I don't know what settings are "working" with my processor.

Overview of my system:

  • Microsoft Surface Pro
  • Intel Core i5-7300U CPU @ 2,60 GHz
  • Microsoft Windows 10 Pro | 64-bit | Version 10.0.18363
  • IDE: Code::Blocks 20.03

Does anyone has an a similar system? Thanks in advance.

Kind Regards

randomcoder


Solution

  • You can always use the flag -march=native, which tells the compiler to detect the CPU of the computer that's being used to compile, and optimize the code for that type of CPU. This is ideal when you are compiling on the same machine you will be running the code on. Note that the resulting executable will not necessarily work on other computers with different CPUs.

    Of course, you also have to use one of the -O options, typically -O2, to get optimizations at all. There are many other specific optimization options, but whether they are helpful will depend on what your program actually does.