Closed VorpalBlade closed 4 months ago
Nothing strange here. sha2
supports autodetection of target features and on x86 it will use SHA-NI instructions if they are available on host CPU. Your AMD CPU has them and the Intel one does not. We know that our software backend is somewhat slower than ring
implementation, see this issue for more information: https://github.com/RustCrypto/hashes/issues/327
Closing in favor of #327
On my desktop ring and sha256 when build with level 2 optimisation and fat LTO are very close in performance. On my older laptop, the same exact binaries has a 1.76x performance difference with ring being faster.
To put this into more specific terms I decided to clone this repo (revision c38787b7abd8dd10412972941d077df54c95a4bb as it happened) and run your sha2 bench on each system. I hope I'm running this correctly:
cargo +nightly bench --package=sha2
is the command I used on both (since you seem to use nightly benching, not criterion).Ring and sha2 doesn't have comparable benchmarks unfortunately, so adapted yours (code at bottom of this issue for adding ring):
Desktop:
Laptop:
I want to stress, this is the exact same binary both machines are running. Something really strange is going on with sha2 here, and whatever that is should be fixed. I would expect both ring and sha2 to scale similarly when moving between machines. Here are the specs for each machine. I expect that it is the CPU that is most interesting.
Desktop:
Laptop:
Both machines have 32 GB RAM. The laptop is a Thinkpad T480. The desktop I built myself myself.
Finally here is the code I added at the end of the sha2 bench (I also ran
cargo add --package=sha2 --dev ring
):Let me know if you need any additional info, because I don't believe sha2 should scale so differently than ring.