Non-scientific hash benchmarks

Which Ruby hash or message digest algorithm is the speediest in Ruby? My cursory Googling didn’t surface an up-to-date benchmark from anyone else so here are some rough results of my own.

Note: These algorithms are not all equivalent so don’t just blindly pick the fastest one! CRC32, MurmurHash, xxHash, and CityHash are all non-cryptographic.

Ruby stdlib:

MD5

SHA1/SHA256/SHA512

Zlib CRC32

Gems:

digest-xxhash v0.2.7 (XXH32/XXH64/XXH3)

murmurhash3 v0.1.7 (32/128)

cityhash v0.9.0 (32/64/128)

openssl v3.2.0 (MD5, SHA1, SHA256, SHA512, SHA3)

Update 2024-03-11: Added OpenSSL::Digest for MD5, SHA1, SHA256, SHA512, and SHA3

Results

100,000 iterations of hashing a 1 MiB blob of random data.

The benchmarks were run on an M1 MacBook Pro.

Apple M1 Pro with 10 CPU cores (8 performance and 2 efficiency)

macOS Sonoma 14.3.1

Ruby 3.3.0

OpenSSL 3.2.1

The benchmark source code is available on GitHub.