C++ 使用数据库提高性能
我最近开始使用PokerFoots库()并设法用它执行一些基本的手/权益评估。不幸的是,当我试图编写计算成本更高的程序时,我遇到了大量性能问题,无法解决这些问题 作为一个例子,我提供了以下程序来计算黑桃a-6手牌对完全随机手牌的平均权益:C++ 使用数据库提高性能,c++,poker,C++,Poker,我最近开始使用PokerFoots库()并设法用它执行一些基本的手/权益评估。不幸的是,当我试图编写计算成本更高的程序时,我遇到了大量性能问题,无法解决这些问题 作为一个例子,我提供了以下程序来计算黑桃a-6手牌对完全随机手牌的平均权益: #include <iostream> #include <vector> #include <pokerstove/penum/ShowdownEnumerator.h> int main() { using name
#include <iostream>
#include <vector>
#include <pokerstove/penum/ShowdownEnumerator.h>
int main() {
using namespace pokerstove;
using namespace std;
CardSet completeDeck;
completeDeck.fill();
cout << "The whole deck has " << completeDeck.size() << " cards" << endl;
CardDistribution anyTwo;
anyTwo.fill(completeDeck, 2);
cout << "There are " << anyTwo.size() << " two card combinations" << endl;
CardDistribution holeCards;
holeCards.parse("As6s");
ShowdownEnumerator showdown;
vector<EquityResult> result = showdown.calculateEquity(
vector<CardDistribution>{anyTwo, holeCards},
CardSet(""),
PokerHandEvaluator::alloc("h")
);
double shareRandom = result.at(0).winShares + result.at(0).tieShares;
double shareHand = result.at(1).winShares + result.at(1).tieShares;
double total = shareRandom + shareHand;
cout << "A random hand has " << shareRandom / total * 100 << " % equity (" << result.at(0).str() << ")" << endl;
cout << "The hand As6s has " << shareHand / total * 100 << " % equity (" << result.at(1).str() << ")" << endl;
}
在我的机器上(我承认不是特别快),这个计算大约需要4分钟!由于这看起来太长了,我认为这个实现肯定有问题(性能方面)
因此,如果有人能指出我哪里做错了/效率低下,我将非常感激
我怀疑可以将随机手的数量从1326减少到169(由于诉讼的等效性),但我没有找到实现这种行为的方法
感谢您的帮助 简单的回答是:这就是它的速度
一个较长的答案是,这个版本是一个通用评估器,能够评估任何类型的游戏。它不做缓存结果、预计算大型表、使用suit同构或其他任何事情。使用探查器查看瓶颈。@Jarod42很明显,
calculateEquity
函数的计算占用了绝大多数时间。我只是不知道如何避免那样。@Gabriel你怎么避免那样?使用分析器。不要猜测瓶颈在哪里。@AndrewHenle现在我猜对了:我已经让valgrind
运行了一个多小时了,我看不到它会很快结束——这样可能是没有希望的。。。总的来说,我正在寻找关于如何更好地使用库的建议。因为我对这个话题还不太熟悉,这里可能有一些人提出了更好的使用这个库的方法。@Gabriel-valgrind
不是性能分析器。假设您在Linux上运行,perf
更符合您的要求:
The whole deck has 52 cards
There are 1326 two card combinations
A random hand has 40.0942 % equity (804780676 36223609 0 0)
The hand As6s has 59.9058 % equity (1220344506 36223609 0 0)