Murmurhash 3 vs md5 vs sipHash vs hashCode (v8)

Revision 8 of this benchmark created on


Preparation HTML

<script src="//rawgithub.com/garycourt/murmurhash-js/master/murmurhash3_gc.js">
</script>
<script src="//rawgithub.com/kvz/phpjs/master/functions/xml/utf8_encode.js"></script>
<script src="//rawgithub.com/kvz/phpjs/master/functions/strings/md5.js">
</script>
<script src="//rawgithub.com/jedisct1/siphash-js/master/lib/siphash.js"></script>

Setup

var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=`[]\\;',./{}|:\"<>?",
      alphabetLength = alphabet.length;
    
    var testStrings = [],
      i = 0,
      j = 0,
      testCount = 100,
      length = 50;
    
    for (i = 0; i < testCount; i++) {
      var newStr = "";
      for (j = 0; j < length; j++) {
        newStr += alphabet[Math.floor((Math.random() * alphabetLength))];
      }
      testStrings[i] = newStr;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
MurmurHash3
for (i = 0; i < testCount; i++) {
  var a = murmurhash3_32_gc(testStrings[i], 6802145);
}
ready
MD5
for (i = 0; i < testCount; i++) {
  md5(testStrings[i]);
}
ready
SipHash
for (i = 0; i < testCount; i++) {
  SipHash.hash([6802145, 0, 0, 0], testStrings[i]);
}
ready
hashCode (like in Java)
for (i = 0; i < testCount; i++) {
  //from http://goo.gl/lY5ww
  var s = 0;
  for (var ii = 0, l = testStrings[i].length; ii < l; ii++) {
    s = ((s << 5) - s) + testStrings[i][ii].charCodeAt(0);
    s = s & s;
  }
}
ready

Revisions

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