Last active
August 1, 2022 13:59
-
-
Save first087/a081b2ae149a315b6006825db8f2c230 to your computer and use it in GitHub Desktop.
[node.js] Test hash count per time
This file contains hidden or 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
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