Created
November 26, 2015 10:55
-
-
Save vigneshshanmugam/d282dc5871881f1b3680 to your computer and use it in GitHub Desktop.
Hashcode test
This file contains 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
'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