I've plotted a short speed comparasion of different hashing algorithms when hashing files.
The individual plots only differ slightly in the reading method and can be ignored here, since all files were stored in a tmpfs. Therefore the benchmark was not IO-Bound if you are wondering.
Algorithms include: SpookyHash, CityHash, Murmur3, MD5, SHA{1,256,512}.
Conclusions:
- Non-cryptographich hasfunctions like Murmur3, Cityhash and Spooky are pretty close together. One should note that Cityhash may be faster on CPUs with SSE 4.2s
CRCinstruction, which my CPU does not have. SpookyHash was in my case always a tiny bit before CityHash. - MD5 seems to be a good tradeoff when using cryptographic hashfunctions, although SHA256 may be more secure to the collision vulnerabilities of MD5 and SHA1.
- The complexity of all algorithms is linear - which is really not surprising since they work blockwise. (I wanted to see if the reading method makes a difference, so you can just compare the rightmost values).
- SHA256 was slower than SHA512.
- I did not investigate the randomness of the hashfunctions. But here is a good comparasion of the hashfunctions that are missing in Ian Boyds answer. This points out that CityHash has some problems in corner cases.
The source used for the plots:
- https://github.com/sahib/rmlint/tree/gh-pages/plots (sorry for the ugly code)
Read full article from Which hashing algorithm is best for uniqueness and speed? - Programmers Stack Exchange
No comments:
Post a Comment