Speed of hashes

Benchmark created on


Description

Test the speed of different hashing algorithms

Setup

const arrayToMakeMap = new Array(500).fill(0);
const mapOfThings = new Map(
	arrayToMakeMap.map((_, index) => {
		return [`${index}`, {
			id: `${index}`
		}];
	})
);

Test runner

Ready to run.

Testing in
TestOps/sec
SHA1
async function createSha1Hash(valueToHash) {
  const encoder = new TextEncoder();
  const decoder = new TextDecoder("utf-8");
  const data = encoder.encode(valueToHash);
  const hashBuffer = await window.crypto.subtle.digest("SHA-1", data);

  return decoder.decode(hashBuffer);
}

let idString = "";
mapOfThings.forEach((thing) => {
	idString += thing.id;	
});

createSha1Hash(idString).then(console.log);
ready
SHA256
async function createSha256Hash(valueToHash) {
  const encoder = new TextEncoder();
  const decoder = new TextDecoder("utf-8");
  const data = encoder.encode(valueToHash);
  const hashBuffer = await window.crypto.subtle.digest("SHA-256", data);

  return decoder.decode(hashBuffer);
}

let idString = "";
mapOfThings.forEach((thing) => {
	idString += thing.id;	
});
  
createSha256Hash(idString).then(console.log);
ready
SHA512
async function createSha512Hash(valueToHash) {
  const encoder = new TextEncoder();
  const decoder = new TextDecoder("utf-8");
  const data = encoder.encode(valueToHash);
  const hashBuffer = await window.crypto.subtle.digest("SHA-512", data);

  return decoder.decode(hashBuffer);
}

let idString = "";
mapOfThings.forEach((thing) => {
	idString += thing.id;	
});
  
createSha512Hash(idString).then(console.log);
ready

Revisions

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