Hash comparison

Benchmark created on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js"></script>

Setup

function generateRandomStrings(count, length) {
  const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  const result = [];
  for (let i = 0; i < count; i++) {
    let str = "";
    for (let j = 0; j < length; j++) {
      str += chars.charAt(Math.floor(Math.random() * chars.length));
    }
    result.push(str);
  }
  return result;
}

// Example: 100 strings, each ~1000 chars long
const testStrings = generateRandomStrings(100, 1000);

Test runner

Ready to run.

Testing in
TestOps/sec
crypto md5
testStrings.map(CryptoJS.MD5);
ready
simple hash
function simpleHash(str) {
  let hash = 0
  for (let i = 0; i < str.length; i++) {
    hash = ((hash << 5) - hash + str.charCodeAt(i)) | 0
  }
  return (hash >>> 0).toString(36)
}

testStrings.map(simpleHash);
ready

Revisions

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