有没有一种方法可以在Mac上启用本地clang ++的优化? [英] is there a way to enable optimization for local clang++ on mac?
问题描述
此问题源自帖子。
似乎在线编译器在优化时会放弃此功能。
it seems that the online compiler discard this function while optimizing.
void functiona()
{
long long number = 0;
// long long problemSize = 100000000000;
long long problemSize = 10;
for( long long i = 0; i < problemSize; ++i )
{
for(long long j = 0; j < problemSize; j++)
{
for(long long k = 0; k < problemSize; k++)
{
for(long long l = 0; l < problemSize; l++)
{
for(long long l = 0; l < problemSize; l++)
{
number++;
number--;
}
}
}
}
}
}
在本地Mac上编译这段代码
$ b
compiling this piece of code on my local mac
clang++ -std=c++11 -stdlib=libc++ benchmark.cpp
./a.out
409
似乎没有优化。
this post and doc provide some info about clang optimization.
是否可以启用clang ++优化,这样本地输出就接近在线输出。
is there a way to enable optimization for clang++, so that the local output is close to online one.
推荐答案
clang ++
与 clang
基本上具有相同的开关,在您自己找到的链接中有完整介绍。最明显的最大优化方法是 -Ofast
,但是鉴于这种优化的简单性和明显性,基本上任何水平的优化都可能触发该优化, -O3
, -02
, -Os
,甚至 -O1
。确切行为会因编译器版本而异,因此您可以尝试确定消除版本循环所需的最低级别。
clang++
takes basically the same switches as clang
, which are fully covered in the links you found on your own. The obvious one for maximum optimization would be -Ofast
, but given how simple and obvious this optimization is, basically any level of optimization is likely to trigger it, -O3
, -02
, -Os
, even -O1
. The exact behavior will vary by compiler version, so you can experiment to determine the minimal level needed to eliminate the loop on your version.
这篇关于有没有一种方法可以在Mac上启用本地clang ++的优化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!