16. January 2007 07:58
Last week, I made a brief post about easily using some of the cryptographic hash algorithms available in the .NET Framework for the purpose of generating a file checksum. After giving it some thought, I decided to do a follow-up post and compare the general performance of each algorithm.
Here is the setup of the test. I wrote a method that accepts the path to a file as a parameter. A stream is opened to read the file and compute the hash. The result of the hash is converted to a string via a BitConverter. The method was cloned for each algorithm being tested: MD5, SHA1, SHA256, SHA384, and SHA512. Each algorithm was tested against a 50K, 100K, 500K, 1MB, and 5MB file. The checksum was calculated for the given file 1000 times to obtain a reasonable measurement. Furthermore, I ran each test three times to obtain an average result. (Refer to my previous post for an example of the code.)
The test was compiled in Release Mode on .NET Framework 2.0. It was executed a computer with a Pentium 4 3.06 Ghz CPU (with Hyper Threading) and 1GB of memory running Windows XP.
Please keep in mind that this was not a certified experiment. It is simply something that I threw together for the sake of curiosity. In other words, draw your own conclusions before accepting the results as a universal law. It isn't meant to be incredibly precise. The point is to emphasize that overall performance decreases as the strength of the hash increases. The difference becomes even more obvious as the size of the file increases.
Here are the results. The times are listed in seconds. This indicates how many seconds it took for the given algorithm to compute a hash 1000 times for the given file size.
| Algorithm | 50 K | | 100 K | | 500 K | | 1 MB | | 5 MB |
| MD5 | 0.359 | | 0.578 | | 2.422 | | 5.13 | | 21.875 |
| SHA1 | 0.781 | | 1.469 | | 7.115 | | 15.427 | | 70.078 |
| SHA256 | 1.109 | | 2.109 | | 9.891 | | 21.807 | | 96.98 |
| SHA384 | 2.688 | | 5.36 | | 26.224 | | 57.656 | | 256.641 |
| SHA512 | 2.703 | | 5.391 | | 26.719 | | 57.691 | | 263.625 |
Here is a chart with the plotted data to give you a better visualization:

0ced82fb-e891-4f19-867f-178781108469|0|.0
By: Jeff Barnes
Category:
Tags: