vector.push_back()提高性能
有什么方法可以改善此功能的性能?正如我必须称其为〜10-100m次以进行1个计算,它正在放慢我的程序,并且大多数时间都在这条线路中丢失了:
myHand_param.FinalHandVector.push_back((1 << static_cast<int>(std::ceil((i - 3.0) / 4.0))));
我知道矢量容量绝不应该超过5,但我不知道如何跳过边界检查,试图与int*一起工作*而不是向量,但也没有帮助。
void CalculateKickers(Hand& myHand_param, int kickersNeeded)
{
int countKickers{ 0 };
for(int i = bits-1; i > 0 ; i--)
{
if (static_cast<std::bitset<bits>>(myHand_param.handMask)[i] == 1)
{
if (static_cast<std::bitset<1>>((static_cast<std::bitset<bits>>(myHand_param.FinalHandUsedCardFacesMask) >> i).to_ullong())== 0)
{
++countKickers;
myHand_param.FinalHandVector.push_back((1 << static_cast<int>(std::ceil((i - 3.0) / 4.0))));
if (countKickers == kickersNeeded)
{
i = 0;
}
}
}
}
}
Is there any way to improve the performance of this function? As I have to call it ~10-100M times for 1 calculation it's slowing down my program and most time has been lost in this line:
myHand_param.FinalHandVector.push_back((1 << static_cast<int>(std::ceil((i - 3.0) / 4.0))));
I know that the vector capacity should never exceed 5 but I don't know how to skip the boundary checking, tried to work with int* instead of vector but it didn't help as well.
void CalculateKickers(Hand& myHand_param, int kickersNeeded)
{
int countKickers{ 0 };
for(int i = bits-1; i > 0 ; i--)
{
if (static_cast<std::bitset<bits>>(myHand_param.handMask)[i] == 1)
{
if (static_cast<std::bitset<1>>((static_cast<std::bitset<bits>>(myHand_param.FinalHandUsedCardFacesMask) >> i).to_ullong())== 0)
{
++countKickers;
myHand_param.FinalHandVector.push_back((1 << static_cast<int>(std::ceil((i - 3.0) / 4.0))));
if (countKickers == kickersNeeded)
{
i = 0;
}
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论