Replies: 2 comments
-
Hi @ucicelos, thanks for your inputs. It's a good idea to export the C/C++ functions for Python directly. Since you created this idea, I'll seek into it. In your code, it looks like |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi @ucicelos , I agree with @HenryRLee about his thoughts on importing the functions in cpp/c. Thanks, Happy Coding. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Henry,
Thanks a lot of sharing this code. It's awesome work. Based on the testing that I did, python version gets to about 100K evaluations per second, pretty fast but a far cry from the CPP numbers.
I haven't done CPP in over 20 years but tried exposing the EvaluateCards through the dll and then used ctypes to call the CPP function from python and got up to 2.2M evaluations per second. Still far from the pure CPP benchmark but over 20 times faster than python implementation.
It's really a hack to get it to work, below is the changes that I made in evaluator.cc, to expose the functions to python. Would love to see a better implementation, would try to see if can do it but posting the code below if anyone else wants to do it.
`
#include <phevaluator/phevaluator.h>
#include "hash.h"
#include "tables.h"
#include
extern "C"
namespace phevaluator {
__declspec(dllexport) int EvaluateCards5(int a, int b, int c, int d,
int e) {
return evaluate_5cards(a, b, c, d, e);
}
__declspec(dllexport) int EvaluateCards6( int a, int b, int c, int d,
int e, int f) {
return evaluate_6cards(a, b, c, d, e, f);
}
__declspec(dllexport) int EvaluateCards7( int a, int b, int c, int d,
int e, int f, int g) {
return evaluate_7cards(a, b, c, d, e, f, g);
}
Rank EvaluateHand(const Hand& hand) {
if (suits[hand.getSuitHash()])
return flush[hand.getSuitBinary()[suits[hand.getSuitHash()]-1]];
const int hash = hash_quinary(hand.getQuinary().data(), hand.size());
switch (hand.size()) {
case 5: return noflush5[hash];
case 6: return noflush6[hash];
case 7: return noflush7[hash];
}
return noflush5[hash];
}
} // namespace phevaluator`
Beta Was this translation helpful? Give feedback.
All reactions