File Checksum Performance Comparison

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:

Comments are closed

About Me

I'm a passionate software developer and advocate of the Microsoft .NET platform.  In my opinion, software development is a craft that necessitates a conscious effort to continually improve your skills rather than falling into the trap of complacency.  I was also awarded as a Microsoft MVP in Connected Systems in 2008, 2009, and 2010.

Can’t code withoutThe best C# & VB.NET refactoring plugin for Visual Studio
Follow jeff_barnes on Twitter

View Jeff Barnes's profile on LinkedIn


Shared Items


Anything you read or see on this site is solely based on my own thoughts.  The material on this site does not necessarily reflect the views of my employer or anyone else.  In other words, I don't speak for anyone other than myself.  So, don't assume I am the official spokesperson for anyone.