This repository has been archived by the owner on Sep 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.js
89 lines (84 loc) · 2.51 KB
/
bench.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const crypto = require('crypto');
const original = require('./original');
const rlbox = require('./rlbox');
const Benchmark = require('benchmark');
Benchmark.options.delay = 5;
Benchmark.options.initCount = 10;
{
Benchmark.options.minSamples = 1000;
const suite = new Benchmark.Suite('genSaltSync');
suite.add('rlbox-genSaltSync', () => {
rlbox.genSaltSync();
})
.add('original-genSaltSync', () => {
original.genSaltSync();
})
.on('cycle', (event) => {
console.log(String(event.target));
})
.on('complete', function () {
console.log(`DONE: ${this[1].name}/${this[0].name} = ${(this[1].hz/this[0].hz)}`);
})
.run({ async: false });
}
{
Benchmark.options.minSamples = 100; // Hashing is pretty slow
const suite = new Benchmark.Suite('hashSync');
// generate sensible random password
const hash = crypto.randomFillSync(Buffer.alloc(32)).toString('hex');
const salt = original.genSaltSync();
suite.add('rlbox-hashSync', () => {
rlbox.hashSync(hash, salt);
})
.add('original-hashSync', () => {
original.hashSync(hash, salt);
})
.on('cycle', (event) => {
console.log(String(event.target));
})
.on('complete', function () {
console.log(`DONE: ${this[1].name}/${this[0].name} = ${(this[1].hz/this[0].hz)}`);
})
.run({ async: false });
}
{
Benchmark.options.minSamples = 1000;
const suite = new Benchmark.Suite('genSalt');
suite.add('rlbox-genSalt', {
defer: true,
fn: (d) => { rlbox.genSalt(() => { d.resolve(); }); }
})
.add('original-genSalt', {
defer: true,
fn: (d) => { original.genSalt(() => { d.resolve(); }); }
})
.on('cycle', (event) => {
console.log(String(event.target));
})
.on('complete', function () {
console.log(`DONE: ${this[1].name}/${this[0].name} = ${(this[1].hz/this[0].hz)}`);
})
.run({ async: false });
}
{
Benchmark.options.minSamples = 100; // Hashing is pretty slow
const suite = new Benchmark.Suite('hash');
// generate sensible random password
const hash = crypto.randomFillSync(Buffer.alloc(32)).toString('hex');
const salt = original.genSaltSync();
suite.add('rlbox-hash', {
defer: true,
fn: (d) => { rlbox.hash(hash, salt, () => { d.resolve(); }); }
})
.add('original-hash', {
defer: true,
fn: (d) => { original.hash(hash, salt, () => { d.resolve(); }); }
})
.on('cycle', (event) => {
console.log(String(event.target));
})
.on('complete', function () {
console.log(`DONE: ${this[1].name}/${this[0].name} = ${(this[1].hz/this[0].hz)}`);
})
.run({ async: true });
}