#include <cstring>
#include <algorithm>
using namespace std;
int t[10000005];
signed main()
{
for (int i = 1; i <= 1000;i++){
fill(t, t + 10000005, 0);
}
return 0;
}
这份代码使用g++ test.cpp -otest && time ./test 编译并运行,结果如下:
real 0m6.582s
user 0m6.553s
sys 0m0.012s
使用 g++ test.cpp -otest -O2 && time ./test 编译并运行,结果如下:
real 0m3.677s
user 0m3.642s
sys 0m0.015s
但是如果在代码中加入 #pragma 并且不使用 -O2:
flyingfrog@fedora:/mnt/Data/OI-training/test$ g++ test.cpp -otest && time ./test
real 0m8.134s
user 0m8.101s
sys 0m0.013s
甚至比不开 pragma 慢了 2s(?
经过多次测试都是如此链接
机房 CPU 为 i5-12500 ,内存 8GB,测试时CPU占用率相差不大且均在较低水平
求大佬解答 QAQ