c - 为什么对 makefile 的更改会使性能提高?

标签 c performance makefile

我最近在类里面完成了一个性能实验室,但我的 friend 向我展示了一件事,我不明白为什么。 在原始的 makefile 中,我们有:

##
##

CXX =g++
CXXFLAGS= -m32 -static

但我将 CXXFLAGS 更改为:

##
##

CXX =g++
CXXFLAGS= -m32 -static -funroll-loops -O3

-funroll-loops -O3 到底做了什么而原始版本没有做的事情?

最佳答案

试试这个:man gcc!

-funroll-loops:

   -funroll-loops
           Unroll loops whose number of iterations can be determined at
           compile time or upon entry to the loop.  -funroll-loops implies
           -frerun-cse-after-loop, -fweb and -frename-registers.  It also
           turns on complete loop peeling (i.e. complete removal of loops with
           a small constant number of iterations).  This option makes code
           larger, and may or may not make it run faster.

-O1:

      -O1 Optimize. Optimizing compilation takes somewhat more time, and a
                 lot more memory for a large function.

                 With -O, the compiler tries to reduce code size and execution time,
                 without performing any optimizations that take a great deal of
                 compilation time.

-O2

  -O2 Optimize even more.  GCC performs nearly all supported
           optimizations that do not involve a space-speed tradeoff.  As
           compared to -O, this option increases both compilation time and the
           performance of the generated code.

-O3

-O3 Optimize yet more.

-O0

  -O0 Reduce compilation time and make debugging produce the expected
           results.  This is the default.

-0s

    -Os Optimize for size.  -Os enables all -O2 optimizations that do not
        typically increase code size.  It also performs further
        optimizations designed to reduce code size.

-Ofast

   -Ofast
       Disregard strict standards compliance.  -Ofast enables all -O3
       optimizations.  It also enables optimizations that are not valid
       for all standard-compliant programs.  It turns on -ffast-math and
       the Fortran-specific -fno-protect-parens and -fstack-arrays.

希望有帮助!

关于c - 为什么对 makefile 的更改会使性能提高?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36731682/

相关文章:

c - 在 C 中加载共享内存

c - 函数和*函数有什么区别?

performance - 数据库速度优化 : few tables with many rows, 或多表少行?

c++ - 为什么程序会跳过带有字符串数组和 cin/cout 的 for 循环

makefile - GNU 制作 : Generating automatic dependencies with generated header files

c - 如何使用链接实现在c中的队列中插入元素

c - 在没有 root 权限的情况下实现共享内存

performance - 了解 Charles 调试代理的计时值

makefile - GNU 制作 : variable for command line arguments

parallel-processing - 如何强制某组目标始终按顺序运行?