我有以下代码,使用 g++ 运行 3 秒,在 microsoft 编译器下运行超过 30 秒,我不明白......
struct constraint{
int bitline;
int result;
};
// this vector is filled with about 1 milion items
vector<constraint> constraints;
for (int a = 0; a < constraints.size(); ++a)
{
if (a% 100 == 0) cout << a << " "<<endl;
for (int b = a; b < constraints.size(); ++b)
{
int anded = constraints[a].bitline & constraints[b].bitline;
int ored = constraints[a].bitline | constraints[b].bitline;
// a subset of b
if (anded == constraints[a].bitline && constraints[a].result >= constraints[b].result )
{
// delete a
constraints[a].bitline = 0;
}
if (anded == constraints[b].bitline && constraints[b].result >= constraints[a].result )
{
constraints[b].bitline = 0;
}
}
}
编辑:我没有使用优化标志,withing。在 windows xp 32 位上运行...在没有“调试 cout 行”的情况下尝试过 - 没有显着变化。