Skip to content

Instantly share code, notes, and snippets.

@first087
Last active August 1, 2022 13:59
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 first087/a081b2ae149a315b6006825db8f2c230 to your computer and use it in GitHub Desktop.
Save first087/a081b2ae149a315b6006825db8f2c230 to your computer and use it in GitHub Desktop.
[node.js] Test hash count per time
const crypto = require('crypto')
const algor = 'sha256' // sha1, sha256
const diffTime = 10 // sec
const test = (nonce) => {
const data = `${Date.now()}${nonce}`
const hash = crypto.createHash(algor).update(data).digest('hex')
// console.log(hash)
}
const startTime = Date.now()
const endTime = startTime + diffTime * 1000
let i = 0
while (Date.now() < endTime) {
test(i++ % 10)
}
console.log(`Hash ${algor} ${i} time in ${diffTime} sec.`)
console.log(`Speed ${i/diffTime} time/sec.`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment