Skip to content

Instantly share code, notes, and snippets.

@vigneshshanmugam
Created November 26, 2015 10:55
Show Gist options
  • Save vigneshshanmugam/d282dc5871881f1b3680 to your computer and use it in GitHub Desktop.
Save vigneshshanmugam/d282dc5871881f1b3680 to your computer and use it in GitHub Desktop.
Hashcode test
'use strict';
const domain = 's3-eu-west-1.amazonaws.com';
const crypto = require('crypto');
function getMd5(str) {
return crypto.createHash('md5').update(str).digest('hex');
}
function getSha1(str) {
return crypto.createHash('sha1').update(str).digest('hex');
}
function getHashCode(str) {
var hash = 0, i, chr, len;
if (str.length == 0) return hash;
for (i = 0, len = str.length; i < len; i++) {
chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
let hrstart = process.hrtime();
for (let i = 0; i < 10000; i++) {
getHashCode(domain);
};
let hrend = process.hrtime(hrstart);
console.info('Execution time (hr): %ds %dms', hrend[0], hrend[1]/1000000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment