Basic hash head-to-head

JavaScript performance comparison

Revision 19 of this test case created by Xotic750

Preparation code

<script src="https://rghost.net/download/44939334/cba84c9732918c489755c25cd42eab0d6efe8d48/utility3.js">
</script>
<script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js">
</script>
<script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha1.js">
</script>
<script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha256.js">
</script>
<script src="https://tiny-sha1.googlecode.com/files/tinySHA1.r4.js">
</script>
<script src="https://bitbucket.org/keesey/sha1/raw/fcbee69dcc6f6e9038e7d78376ab207e0816896a/bin/sha1.js">
</script>
<script src="https://www.movable-type.co.uk/scripts/utf8.js">
</script>
<script src="https://www.movable-type.co.uk/scripts/sha1.js">
</script>
<script src="https://www.movable-type.co.uk/scripts/sha256.js">
</script>
<script src="https://rghost.net/download/44852684/c85b0e31d1aba661bdb7b45e4919cbcb59c67add/sha_dev.jss">
</script>
<script src="http://www.myersdaily.org/joseph/javascript/md5.js"></script>
<script>
  var s = "",
      a = [];

  $u.range(0, 9).forEach(function() {
    a.push(s);
  });

  $u.range(1, 257).forEach(function(part) {
    s = "";
    $u.range(0, 255).forEach(function(character) {
      s += String.fromCharCode(part * character);
    });

    a.push(s);
  });

  a.push(a.join(''));
</script>
    

Preparation code output

<script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"> </script> <script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha1.js"> </script> <script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha256.js"> </script> <script src="https://tiny-sha1.googlecode.com/files/tinySHA1.r4.js"> </script> <script src="https://bitbucket.org/keesey/sha1/raw/fcbee69dcc6f6e9038e7d78376ab207e0816896a/bin/sha1.js"> </script> <script src="https://www.movable-type.co.uk/scripts/utf8.js"> </script> <script src="https://www.movable-type.co.uk/scripts/sha1.js"> </script> <script src="https://www.movable-type.co.uk/scripts/sha256.js"> </script> <script src="https://rghost.net/download/44852684/c85b0e31d1aba661bdb7b45e4919cbcb59c67add/sha_dev.jss"> </script> <script src="http://www.myersdaily.org/joseph/javascript/md5.js"></script> <script> var s = "", a = []; $u.range(0, 9).forEach(function() { a.push(s); }); $u.range(1, 257).forEach(function(part) { s = ""; $u.range(0, 255).forEach(function(character) { s += String.fromCharCode(part * character); }); a.push(s); }); a.push(a.join('')); </script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
CryptoJs md5
a.forEach(function(str) {
  CryptoJS.MD5(str).toString();
});

// handles the first 225 tests and then fails, otherwise had matching hashes, passing it a utf8encoded string causes the hashes to be incorrect.
pending…
utility md5
a.forEach(function(str) {
  $u.md5(str);
});
pending…
CryptoJs sha1
a.forEach(function(str) {
  CryptoJS.SHA1(str).toString();
});

// handles the first 225 tests and then fails, otherwise had matching hashes, passing it a utf8encoded string causes the hashes to be incorrect.
pending…
utility sha1
a.forEach(function(str) {
  $u.sha1(str);
});
pending…
tiny sha1
throw new Error("Fails to match hashes produced by other routines, irrespective of utf8");
a.forEach(function(str) {
  SHA1(str);
});
pending…
movable-type sha1
a.forEach(function(str) {
  Sha1.hash(str, true);
});
pending…
other sha1
throw new Error("Fails to match hashes produced by other routines, irrespective of utf8");
a.forEach(function(str) {
  sha1.hash(str);
});
pending…
jssha sha1
a.forEach(function(str) {
  (new jsSHA($u.utf8Encode(str), 'TEXT')).getHash('SHA-1', 'HEX');
});
pending…
CryptoJs sha256
a.forEach(function(str) {
  CryptoJS.SHA256(str).toString();
});

// handles the first 225 tests and then fails, otherwise had matching hashes, passing it a utf8encoded string causes the hashes to be incorrect.
pending…
utility sha256
a.forEach(function(str) {
  $u.sha256(str);
});
pending…
movable-type sha256
a.forEach(function(str) {
  Sha256.hash(str, true);
});
pending…
jssha sha256
a.forEach(function(str) {
  (new jsSHA($u.utf8Encode(str), 'TEXT')).getHash('SHA-256', 'HEX');
});
pending…
check sha1's
a.forEach(function(str, index) {
  var //sw1 = CryptoJS.SHA1((str)).toString(),
      //sw2 = sha1.hash(str),
      sw3 = Sha1.hash(str, true),
      //sw4 = SHA1(str),
      sw5 = $u.sha1(str),
      sw6 = (new jsSHA($u.utf8Encode(str), 'TEXT')).getHash('SHA-1', 'HEX'),
      //t1 = sw5 === sw1,
      //t2 = sw5 === sw2,
      t3 = sw5 === sw3,
      //t4 = sw5 === sw4,
      t5 = sw5 === sw6;

  if (!t3 || !t5) {
    console.error(index, [t3, t5]);
    throw new Error("mismatch index: " + index + " " + [t3, t5].toString());
  }
});
pending…
check sha256's
a.forEach(function(str, index) {
  var //sw1 = CryptoJS.SHA256((str)).toString(),
      sw2 = Sha256.hash(str, true),
      sw3 = $u.sha256(str),
      sw4 = (new jsSHA($u.utf8Encode(str), 'TEXT')).getHash('SHA-256', 'HEX'),
      //t1 = sw3 === sw1,
      t2 = sw3 === sw2,
      t3 = sw3 === sw4;

  if (!t2 || !t3) {
    console.error(index, [t2, t3]);
    throw new Error("mismatch index: " + index + " " + [t2, t3].toString());
  }
});
pending…
Joseph's Myers md5
a.forEach(function(str) {
  md5($u.utf8Encode(str));
});
pending…
check md5's
a.forEach(function(str, index) {
  var //sw1 = CryptoJS.MD5((str)).toString(),
      sw2 = $u.md5(str),
      sw3 = md5($u.utf8Encode(str)),
      //t1 = sw2 === sw1,
      t2 = sw2 === sw3;

  if (!t2) {
    console.error(index, [t2]);
    throw new Error("mismatch index: " + index + " " + [t2].toString());
  }
});
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments