hashing test

Benchmark created on


Preparation HTML

<script src="https://unpkg.com/object-hash@3.0.0/dist/object_hash.js"></script>

<script>

function hash2(str) {
  var hash = 0,
    i, chr;
  if (str.length === 0) return hash;
  for (i = 0; i < str.length; i++) {
    chr = str.charCodeAt(i);
    hash = ((hash << 5) - hash) + chr;
    hash |= 0; // Convert to 32bit integer
  }
  return hash;
}

const cyrb53 = (str, seed = 0) => {
    let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
    for(let i = 0, ch; i < str.length; i++) {
        ch = str.charCodeAt(i);
        h1 = Math.imul(h1 ^ ch, 2654435761);
        h2 = Math.imul(h2 ^ ch, 1597334677);
    }
    h1  = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
    h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
    h2  = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
    h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
  
    return 4294967296 * (2097151 & h2) + (h1 >>> 0);
};

</script>

<script>
var ARGS = {
	uri: 'https://www.example.com/video.mp4',
	x: 199,
	y: 200,
	width: 1920,
	height: 1080
}
</script>

Setup


Test runner

Ready to run.

Testing in
TestOps/sec
object_hash sha1
var hash = objectHash.sha1(ARGS);
ready
java hash
var str = ARGS.uri + '|' + ARGS.x + '|' + ARGS.y + '|' | ARGS.width + '|' + ARGS.height;
var hash = hash2(str);
ready
cyrb53
var str = ARGS.uri + '|' + ARGS.x + '|' + ARGS.y + '|' | ARGS.width + '|' + ARGS.height;
var hash = cyrb53(str);
ready
object_hash md5
var hash = objectHash.MD5(ARGS);
ready

Revisions

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