Created
September 3, 2022 05:10
-
-
Save azole/79a403cdb6cefcc89c726c1271bee6af to your computer and use it in GitHub Desktop.
Hash-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
const argon2 = require('argon2'); | |
let plainPasswords = ['asdfwrwsdf', 'aserqwr&134sfasefr', 'asfw423d', 'asf8w4@w3423', 'qqsfw40#sjr#', 'PassW0rd', 'administartor']; | |
let len = plainPasswords.length; | |
let hashedPassword = []; | |
async function argon2Hash(count) { | |
console.time('argon2'); | |
for (let i = 0; i < count; i++) { | |
const hash = await argon2.hash(plainPasswords[i % len], 10); | |
hashedPassword.push(hash); | |
} | |
console.timeEnd('argon2'); | |
} | |
async function argon2Compare(count) { | |
console.time('argon2Compare'); | |
for (let i = 0; i < count; i++) { | |
const result = await argon2.verify(hashedPassword[i % len], plainPasswords[i % len]); | |
} | |
console.timeEnd('argon2Compare'); | |
} | |
(async () => { | |
await argon2Hash(1000); | |
argon2Compare(1000); | |
})(); | |
// mac intel | |
// ❯ node hash-argon2.js | |
// argon2: 6.758s | |
// argon2Compare: 6.579s | |
// ❯ node hash-argon2.js | |
// argon2: 6.708s | |
// argon2Compare: 6.612s |
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
const bcrypt = require('bcrypt'); | |
let plainPasswords = ['asdfwrwsdf', 'aserqwr&134sfasefr', 'asfw423d', 'asf8w4@w3423', 'qqsfw40#sjr#', 'PassW0rd', 'administartor']; | |
let len = plainPasswords.length; | |
let hashedPassword = []; | |
async function bcryptHash(count) { | |
console.time('bcrypt'); | |
for (let i = 0; i < count; i++) { | |
const hash = await bcrypt.hash(plainPasswords[i % len], 10); | |
hashedPassword.push(hash); | |
} | |
console.timeEnd('bcrypt'); | |
} | |
async function bcryptCompare(count) { | |
console.time('bcrypt'); | |
for (let i = 0; i < count; i++) { | |
const result = await bcrypt.compare(plainPasswords[i % len], hashedPassword[i % len]); | |
} | |
console.timeEnd('bcrypt'); | |
} | |
// 兩個測試分開,不然會互搶 CPU | |
(async () => { | |
await bcryptHash(1000); | |
bcryptCompare(1000); | |
})(); | |
// mac intel | |
// ❯ node hash-bcrypt.js | |
// bcrypt: 1:08.367 (m:ss.mmm) | |
// bcrypt: 1:08.275 (m:ss.mmm) | |
// ❯ node hash-bcrypt.js | |
// bcrypt: 1:08.429 (m:ss.mmm) | |
// bcrypt: 1:08.302 (m:ss.mmm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment