Last active
June 17, 2025 07:31
-
-
Save keepitsimple/d36e9c13c6610c0e394303543aa87e1e to your computer and use it in GitHub Desktop.
Node.js fastest hash function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just example data