Skip to content

Instantly share code, notes, and snippets.

@jay3sh
Created April 9, 2014 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jay3sh/10288621 to your computer and use it in GitHub Desktop.
Save jay3sh/10288621 to your computer and use it in GitHub Desktop.
node.js crypto algorithm comparision
var crypto = require('crypto');
function run(algo) {
var hash = crypto.createHash(algo);
hash.update('operation');
hash.update('1');
hash.update('A34');
hash.update('ABS');
return hash.digest('hex');
}
function loop(algo) {
var start = new Date().getTime();
for(var i=0; i<1000000; i++) {
run(algo);
}
var end = new Date().getTime();
return end-start;
}
console.log('md5',run('md5').length, loop('md5'));
console.log('sha1',run('sha1').length, loop('sha1'));
console.log('sha256',run('sha256').length, loop('sha256'));
/*
Output of sample run (times in millisecond)
md5 32 2810
sha1 40 2954
sha256 64 3311
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment