deus-x-mackina / poker

A Rust crate for evaluating poker hands
MIT License
12 stars 5 forks source link

Evaluator::evaluate could be 10x faster #6

Closed gustafbergmark closed 1 year ago

gustafbergmark commented 1 year ago

I was trying out the evaluator and noticed that 85% of the evaluation time was spent onall_unique(), while about 8% was spent on five, which seems to be what is actually evaluating the hand. I feel that it would be reasonable to allow the user to opt out of this all_unique() call for increased performance.

deus-x-mackina commented 1 year ago

Thank you for submitting an issue!

I still think it's important to ensure the hand has unique cards in order to evaluate. I understand the desire to opt out, as most well-meaning users wouldn't submit a hand with duplicates, but having a unique set of cards is an invariant for evaluation and should be checked just in case. In order to partially address the performance issue, I've tweaked a) the implementation of all_unique to not use a HashSet anymore (which greatly improved performance), and I also fixed some of the internal evaluation implementation that boosted performance a little bit more. All in all, the bost is ~30% faster. Check 3d97690c0b515ee6c0e46bf07565b49e89b37b31 and 1a5e97d4a441f0433b9bc886f8d30338365a2352.