And it is a fair comparison because the Linux I’m running (Ubuntu 24.04 LTS) runs on my Windows 11 box in a hyper-V VM. I wrote a Poker hand evaluation program which loaded a text file containing lines of seven playing cards in text format TS 2C 4D sort of thing. It was seven cards because there’s two in your hand and five on the table.
There were 1,000 lines of these and the program loaded the file into memory, holding the cards in a Vec<Vec<Card>>. Then it loops through the 1,000 elements and figures out the best hand for each set. The bit that was timed was the loop not the loading the file into memory.
The source file is on GitHub. It has the project files plus some test cards. You can try it yourself. Note at the bottom of this article is a link to a much faster version.
https://github.com/David-H-Bolton/Projects/blob/main/rust_pokerhand.zip
On my PC, the Windows one average time per hand is 768 ns. On Ubuntu is 540ns. Mad eh! The same program runs in 70% of the time on Linux compared to Windows. Both are run with this command from a terminal/command line.
cargo run --release 1000_card_hads.txt
You can also try the test_card_hands.txt but you need to enable the show_cards feature. That shows the cards but doesn’t do timing. The default is do the timing but don’t show the cards or the evaluation.
cargo run --release --features show_card test_card_hands.txt
The test cards say what each hand is and the output at the bottom is the program working out each hand.
The file
https://github.com/David-H-Bolton/Projects/blob/main/rust_pokerhand_faster.zip
contains a much faster version. On Linux it takes about 127 ns per hand. On Windows it’s about 190 ns.