使用O3优化级别编译GSL

时间:2023-01-11 02:12:54

My program heavily depends on the special functions from GSL and thus I would like to make it run faster, so I wish to compile GSL with higher optimization levels.

我的程序在很大程度上取决于GSL的特殊功能,因此我想让它运行得更快,所以我希望用更高的优化级别编译GSL。

When I compile gsl, the default CFLAGS is "-g -O2" if I do nothing when I configure with "./configure". I am wondering why gsl is defaulting to an optimization level of O2 only since O3 is compliant to standards. I tried to compile and test with "./configure CFLAGS='-g -O3'", things worked. But I'm still not sure if everything would work.

当我编译gsl时,如果我在配置“./configure”时什么都不做,那么默认的CFLAGS是“-g -O2”。我想知道为什么gsl默认为O2的优化级别,因为O3符合标准。我尝试用“./configure CFLAGS =' - g -O3'”进行编译和测试,事情很有效。但我仍然不确定一切是否会奏​​效。

Can anyone tell me why GSL is defaulting to O2 instead of O3? Would it be dangerous if I default to O3? Thanks!

谁能告诉我为什么GSL默认为O2而不是O3?如果我默认为O3会不会很危险?谢谢!

1 个解决方案

#1


2  

The optimization level 3 is something that should only be used in case it is absolutely sure that it helps the library.

优化级别3只应该用于绝对确定它有助于库的情况。

Since that level activates optimizations that may increase the size of the code a lot. This means in some cases it creates binaries that are even slower compared to a binary optimized with -O2. How ever that happens rarely. More likely are effects like a massively increased time to compile it, along with a increased binary size and a barely measurable performance change.

由于该级别激活了可能会大大增加代码大小的优化。这意味着在某些情况下,与使用-O2优化的二进制文件相比,它会创建更慢的二进制文件。怎么会这很少发生。更有可能的是诸如大量增加编译时间的效果,以及增加的二进制大小和几乎不可测量的性能变化。

That -O3 actually breaks something was pretty common some time back, but in the last couple of years I did not have a single case where -O3 actually optimized something that caused the binary to break.

事实上-O3实际上已经破坏了某些东西,但在过去的几年里,我没有一个案例,其中-O3实际上优化了导致二进制文件破坏的东西。

In the end the optimization level is something you can just test. Since -O2 is the default, it is a pretty safe bet that this is the best settings for the compile operation in this case. If you feel like it you could try to compile it with a different setting to see if it makes any performance difference.

最后,优化级别是您可以测试的。由于-O2是默认值,因此可以肯定的是,在这种情况下,这是编译操作的最佳设置。如果您愿意,可以尝试使用不同的设置对其进行编译,以查看它是否会产生任何性能差异。

Interesting options are -O3 and even -Os. I had cases in the past were both options gave improved performance over -O2.

有趣的选择是-O3和偶数-Os。我过去的情况都是两种选择都提高了-O2的性能。

So the real answer is: Try it and see what happens.

所以真正的答案是:尝试一下,看看会发生什么。

#1


2  

The optimization level 3 is something that should only be used in case it is absolutely sure that it helps the library.

优化级别3只应该用于绝对确定它有助于库的情况。

Since that level activates optimizations that may increase the size of the code a lot. This means in some cases it creates binaries that are even slower compared to a binary optimized with -O2. How ever that happens rarely. More likely are effects like a massively increased time to compile it, along with a increased binary size and a barely measurable performance change.

由于该级别激活了可能会大大增加代码大小的优化。这意味着在某些情况下,与使用-O2优化的二进制文件相比,它会创建更慢的二进制文件。怎么会这很少发生。更有可能的是诸如大量增加编译时间的效果,以及增加的二进制大小和几乎不可测量的性能变化。

That -O3 actually breaks something was pretty common some time back, but in the last couple of years I did not have a single case where -O3 actually optimized something that caused the binary to break.

事实上-O3实际上已经破坏了某些东西,但在过去的几年里,我没有一个案例,其中-O3实际上优化了导致二进制文件破坏的东西。

In the end the optimization level is something you can just test. Since -O2 is the default, it is a pretty safe bet that this is the best settings for the compile operation in this case. If you feel like it you could try to compile it with a different setting to see if it makes any performance difference.

最后,优化级别是您可以测试的。由于-O2是默认值,因此可以肯定的是,在这种情况下,这是编译操作的最佳设置。如果您愿意,可以尝试使用不同的设置对其进行编译,以查看它是否会产生任何性能差异。

Interesting options are -O3 and even -Os. I had cases in the past were both options gave improved performance over -O2.

有趣的选择是-O3和偶数-Os。我过去的情况都是两种选择都提高了-O2的性能。

So the real answer is: Try it and see what happens.

所以真正的答案是:尝试一下,看看会发生什么。