9

Which hash algorithm takes longer time to compute if we compare between md5 and sha256?

I do not want to use it for security reasons so I do not care about which one is more secure, I just want to know which one takes fewer time than the other.

5
  • sha1256 ?? or something else ?
    – user45139
    Commented Aug 2, 2015 at 6:44
  • 1
    @begueradj sorry 1 typed by mistake, I have edited the question.
    – Mo Haidar
    Commented Aug 2, 2015 at 6:49
  • Note that if you're not using it for security, you probably don't want to use (relatively slow) hash functions like MD5 and SHA2! Commented Aug 2, 2015 at 14:37
  • @RensvanderHeijden, so which algorithm should I use.
    – Mo Haidar
    Commented Aug 2, 2015 at 15:05
  • It depends on the use case -- if you want to check redundancy, you'd use something like CRC. If you're using it for a data structure, you'll want to use the programming languages' built-in hash function (see e.g. this question). There are many more use cases though. For an overview and more example hash functions, see wikipedia. Commented Aug 2, 2015 at 15:08

2 Answers 2

15

It depends on the hardware and software you are running. Below are comparison results between MD5 and SHA using the openssl library on my computer. But different implementations that take into account hardware acceleration will give different results. Modern CPUs have hardware acceleration for hash functions. GPUs will have better results and specialised hardware exists to accelerate hashing even further. That is especially true for SHA because it is used for crypto currency mining.

$ openssl speed md5 sha1 sha256

type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
md5              58318.02k   171878.31k   370689.37k   502232.78k   580493.45k
sha1             69045.26k   188431.38k   385979.53k   543316.53k   625854.82k
sha256           49638.66k   107537.27k   183872.51k   226793.47k   237228.26k

The 'numbers' are in 1000s of bytes per second processed.

2021 update with OpenSSL 1.1.1d: now we see md5 is often slower on newer CPU, and for larger chunks:

## PC i7-1165G7 @ 2.80GHz (2020)
OpenSSL 1.1.1d  10 Sep 2019 / built on: Mon Dec  7 20:44:45 2020 UTC
type      16 bytes    64 bytes    256 bytes   1024 bytes   8192 bytes  16384 bytes
md5     189018.70k  418310.85k   712090.28k   890189.14k   956293.12k   962560.00k
sha1    287134.62k  746529.17k  1474064.38k  1973607.08k  2197842.60k  2192179.20k
sha256  222301.71k  603962.47k  1213340.33k  1665262.59k  1849016.32k  1847388.84k

## Server AMD EPYC 7571 (2018)
OpenSSL 1.1.1d  10 Sep 2019 / built on: Mon Dec  7 20:44:45 2020 UTC
type      16 bytes    64 bytes    256 bytes   1024 bytes   8192 bytes  16384 bytes
md5      93668.33k  213979.18k   378971.56k   467472.38k   501205.67k   504064.68k
sha1    165020.82k  442991.72k   888443.48k  1188591.62k  1319236.95k  1330080.43k
sha256  142886.55k  375612.63k   791567.70k  1095950.34k  1234381.48k  1246827.86k

## Server E5-2682 v4 @ 2.50GHz (2016)
OpenSSL 1.1.1d  10 Sep 2019 / built on: Mon Dec  7 20:44:45 2020 UTC
type      16 bytes    64 bytes    256 bytes   1024 bytes   8192 bytes  16384 bytes
md5     101505.24k  207422.92k   393158.83k   453332.99k   527085.34k   490711.72k
sha1     98091.83k  249828.79k   389640.36k   675694.25k   686966.33k   721021.61k
sha256   55421.86k  130103.33k   251929.17k   302571.86k   296977.81k   338439.56k
1
  • 1
    Did not know this possibility of the openssl command line utility. Thanks!
    – mljrg
    Commented Oct 31, 2019 at 16:30
8

MD5 is known to be generally faster than SHA256. You can confirm that on this page, for example.

OpenSSL for example has a built-in benchmark suit, so you can compare yourself by running:

$ openssl speed md5 
$ openssl speed sha256

But of course, the hardware and software you use to compare them can make difference. You can see the results this user got on his 32 and 64 bits, but I think this comparison table is widely enough to judge MD5 being faster than SHA256.

1
  • 2
    You can also compare multiple algorithms in one command: openssl speed md5 sha256. Or all of them at once with openssl speed, although benchmarking them all will take a fair while.
    – mwfearnley
    Commented Apr 28, 2021 at 12:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .