-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bench(bcrypt): add @cwasm/openbsd-bcrypt and @cwasm/openwall-bcrypt t…
…o benchmark (#649) * Add @cwasm/openbsd-bcrypt and @cwasm/openwall-bcrypt to benchmark * tinybench --------- Co-authored-by: LongYinan <[email protected]>
- Loading branch information
1 parent
5232a7e
commit 50be77d
Showing
12 changed files
with
482 additions
and
241 deletions.
There are no files selected for viewing
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
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import openbsd from '@cwasm/openbsd-bcrypt' | ||
import openwall from '@cwasm/openwall-bcrypt' | ||
import { hashSync, compare, genSaltSync } from 'bcrypt' | ||
import bcryptjs from 'bcryptjs' | ||
import { Bench } from 'tinybench' | ||
import chalk from 'chalk' | ||
|
||
import { hashSync as napiHashSync, verifySync, genSaltSync as napiGenSaltSync } from '../binding.js' | ||
|
||
const password = 'node-rust-password' | ||
|
||
const syncHashSuite = new Bench() | ||
syncHashSuite | ||
.add('@node-rs/bcrypt', () => { | ||
napiHashSync(password, 10) | ||
}) | ||
.add('node bcrypt', () => { | ||
hashSync(password, 10) | ||
}) | ||
.add('bcryptjs', () => { | ||
bcryptjs.hashSync(password, 10) | ||
}) | ||
.add('wasm OpenBSD', () => { | ||
openbsd.hashSync(password, 10) | ||
}) | ||
.add('wasm Openwall', () => { | ||
openwall.hashSync(password, 10) | ||
}) | ||
|
||
await syncHashSuite.warmup() | ||
await syncHashSuite.run() | ||
|
||
console.info(chalk.green('Hash benchmark')) | ||
console.table(syncHashSuite.table()) | ||
|
||
const verifySuite = new Bench() | ||
const hashed = napiHashSync(password, 12) | ||
verifySuite | ||
.add('@node-rs/bcrypt', () => { | ||
verifySync(password, hashed) | ||
}) | ||
.add('node bcrypt', () => { | ||
compare(password, hashSync(password, 12)) | ||
}) | ||
.add('bcryptjs', () => { | ||
bcryptjs.compareSync(password, hashed) | ||
}) | ||
|
||
await verifySuite.warmup() | ||
await verifySuite.run() | ||
|
||
console.info(chalk.green('Verify benchmark')) | ||
console.table(verifySuite.table()) | ||
|
||
const genSaltSuite = new Bench() | ||
genSaltSuite | ||
.add('@node-rs/bcrypt', () => { | ||
napiGenSaltSync(12) | ||
}) | ||
.add('node bcrypt', () => { | ||
genSaltSync(12) | ||
}) | ||
.add('bcryptjs', () => { | ||
bcryptjs.genSaltSync(12) | ||
}) | ||
.add('wasm OpenBSD', () => { | ||
openbsd.genSaltSync(12) | ||
}) | ||
.add('wasm Openwall', () => { | ||
openwall.genSaltSync(12) | ||
}) | ||
|
||
await genSaltSuite.warmup() | ||
await genSaltSuite.run() | ||
|
||
console.info(chalk.green('GenSalt benchmark')) | ||
console.table(genSaltSuite.table()) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
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
Oops, something went wrong.