This page uses 0 trackers, and 0 cookies! (I don't
even know if anyone reads these, lemme know if you do via Mastodon)
I compared 14 hashing algorithms on Rust using Criterion
A vital piece of technologies in modern days is the hashing function, a function that takes in some input and returns a non-meaningful and unique output.
(As you can see, there’s no pattern)
As hash functions just take a sequence of bits, they are used in lots of scenarios. From vital (mostly builtin) structures like the HashMap, to authenticating users without storing their plain-text password, to detecting if a file has changed by storing its hash and checking it continuously.
So yeah, their useful. But I’m focused on performance, I’m the kind of person that obsesses with numbers, that tries to use the least number of electrons to perform a task, that values user’s time and computer resources more than gold. So…
What hashing algorithm is the best?
There are lots of hashing algorithms, some (like blake3) are secure in the cryptographic sense, meaning that they can be used for encryption without worrying about your data being unencrypted by a malicious actor. While others (like MD5) are not suitable for those purposes but excel in their ease of implementation.
As I wanted to check if the hashing algorithm used in the Rust compiler was optimal, I didn’t care for security, just speed.
After publishing about my efforts, Ed Page reached to me about adding these benchmarks to his the rosetta-rs project
OK but where are the numbers
These benchmarks were measured on Wikipedia articles, for the full Criterion benchmark see here.