Skip to content

Instantly share code, notes, and snippets.

@keepitsimple
Last active June 17, 2025 07:31
Show Gist options
  • Save keepitsimple/d36e9c13c6610c0e394303543aa87e1e to your computer and use it in GitHub Desktop.
Save keepitsimple/d36e9c13c6610c0e394303543aa87e1e to your computer and use it in GitHub Desktop.
Node.js fastest hash function
const crypto = require('crypto');
console.time('hash')
const hash = crypto.createHash('md5').update(str).digest("hex");
console.timeEnd('hash')
console.log(hash)
// sha1 function is 4-5x times faster on my computer than md5
console.time('hash2')
const hash2 = crypto.createHash('sha1').update(str).digest("base64");
console.timeEnd('hash2')
console.log(hash2)
// sha256 function is 2-3x times faster on my computer than sha1
console.time('hash3')
const hash3 = crypto.createHash('sha256').update(str).digest("base64");
console.timeEnd('hash3')
console.log(hash3)
@keepitsimple
Copy link
Author

Just example data

hash: 0.788ms
534ccbd2633050b15783bb612f7a7905
hash2: 0.125ms
vt4KSjPwm7acaqRVsM9zmww1qic=
hash3: 0.066ms
nkpn6LT0MRk9TCuDeuUiY/zWaTMb+EbM8f5KHw8QjmQ=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment