Skip to content

Instantly share code, notes, and snippets.

@dszakallas
Created January 27, 2017 22:20
Show Gist options
  • Save dszakallas/b569e77c9c9c22f66bf63e85598a8569 to your computer and use it in GitHub Desktop.
Save dszakallas/b569e77c9c9c22f66bf63e85598a8569 to your computer and use it in GitHub Desktop.
benchmark hashes
'use strict'
var crypto = require('crypto')
var promise = Promise.resolve()
var data = []
for (var i = 0; i < 1e5; ++i) {
promise = promise.then(function () {
return new Promise(function (resolve, reject) {
crypto.randomBytes(256, (err, buf) => {
if (err) {
return reject(err)
}
data.push(buf.toString('base64'))
return resolve()
})
})
})
}
var hasher
promise.then(function () {
['md4', 'md5', 'sha1', 'sha256'].forEach(function (h) {
console.log(h)
for (var j = 1; j < 10; ++j) {
var start = process.hrtime()
for (var i = 0; i < data.length; ++i) {
hasher = crypto.createHash(h)
hasher.update(data[i])
hasher.digest('hex')
}
console.log(process.hrtime(start))
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment