Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0851822

Browse filesBrowse files
BridgeARMylesBorins
authored andcommitted
benchmark: (crypto) refactor
PR-URL: #18320 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent cb13c7c commit 0851822
Copy full SHA for 0851822

File tree

Expand file treeCollapse file tree

7 files changed

+35
-40
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+35
-40
lines changed
Open diff view settings
Collapse file

‎benchmark/crypto/aes-gcm-throughput.js‎

Copy file name to clipboardExpand all lines: benchmark/crypto/aes-gcm-throughput.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ const bench = common.createBenchmark(main, {
88
len: [1024, 4 * 1024, 16 * 1024, 64 * 1024, 256 * 1024, 1024 * 1024]
99
});
1010

11-
function main(conf) {
12-
const message = Buffer.alloc(conf.len, 'b');
13-
const key = crypto.randomBytes(keylen[conf.cipher]);
11+
function main({ n, len, cipher }) {
12+
const message = Buffer.alloc(len, 'b');
13+
const key = crypto.randomBytes(keylen[cipher]);
1414
const iv = crypto.randomBytes(12);
1515
const associate_data = Buffer.alloc(16, 'z');
1616
bench.start();
17-
AEAD_Bench(conf.cipher, message, associate_data, key, iv, conf.n, conf.len);
17+
AEAD_Bench(cipher, message, associate_data, key, iv, n, len);
1818
}
1919

2020
function AEAD_Bench(cipher, message, associate_data, key, iv, n, len) {
Collapse file

‎benchmark/crypto/cipher-stream.js‎

Copy file name to clipboardExpand all lines: benchmark/crypto/cipher-stream.js
+9-10Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const bench = common.createBenchmark(main, {
99
api: ['legacy', 'stream']
1010
});
1111

12-
function main(conf) {
13-
var api = conf.api;
12+
function main({ api, cipher, type, len, writes }) {
1413
if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) {
1514
console.error('Crypto streams not available until v0.10');
1615
// use the legacy, just so that we can compare them.
@@ -33,33 +32,33 @@ function main(conf) {
3332
// alice_secret and bob_secret should be the same
3433
assert(alice_secret === bob_secret);
3534

36-
const alice_cipher = crypto.createCipher(conf.cipher, alice_secret);
37-
const bob_cipher = crypto.createDecipher(conf.cipher, bob_secret);
35+
const alice_cipher = crypto.createCipher(cipher, alice_secret);
36+
const bob_cipher = crypto.createDecipher(cipher, bob_secret);
3837

3938
var message;
4039
var encoding;
41-
switch (conf.type) {
40+
switch (type) {
4241
case 'asc':
43-
message = 'a'.repeat(conf.len);
42+
message = 'a'.repeat(len);
4443
encoding = 'ascii';
4544
break;
4645
case 'utf':
47-
message = 'ü'.repeat(conf.len / 2);
46+
message = 'ü'.repeat(len / 2);
4847
encoding = 'utf8';
4948
break;
5049
case 'buf':
51-
message = Buffer.alloc(conf.len, 'b');
50+
message = Buffer.alloc(len, 'b');
5251
break;
5352
default:
54-
throw new Error(`unknown message type: ${conf.type}`);
53+
throw new Error(`unknown message type: ${type}`);
5554
}
5655

5756
const fn = api === 'stream' ? streamWrite : legacyWrite;
5857

5958
// write data as fast as possible to alice, and have bob decrypt.
6059
// use old API for comparison to v0.8
6160
bench.start();
62-
fn(alice_cipher, bob_cipher, message, encoding, conf.writes);
61+
fn(alice_cipher, bob_cipher, message, encoding, writes);
6362
}
6463

6564
function streamWrite(alice, bob, message, encoding, writes) {
Collapse file

‎benchmark/crypto/get-ciphers.js‎

Copy file name to clipboardExpand all lines: benchmark/crypto/get-ciphers.js
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ const bench = common.createBenchmark(main, {
77
v: ['crypto', 'tls']
88
});
99

10-
function main(conf) {
11-
const n = +conf.n;
12-
const v = conf.v;
10+
function main({ n, v }) {
1311
const method = require(v).getCiphers;
1412
var i = 0;
15-
// first call to getChipers will dominate the results
13+
// First call to getChipers will dominate the results
1614
if (n > 1) {
1715
for (; i < n; i++)
1816
method();
Collapse file

‎benchmark/crypto/hash-stream-creation.js‎

Copy file name to clipboardExpand all lines: benchmark/crypto/hash-stream-creation.js
+7-8Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ const bench = common.createBenchmark(main, {
1313
api: ['legacy', 'stream']
1414
});
1515

16-
function main(conf) {
17-
var api = conf.api;
16+
function main({ api, type, len, out, writes, algo }) {
1817
if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) {
1918
console.error('Crypto streams not available until v0.10');
2019
// use the legacy, just so that we can compare them.
@@ -23,26 +22,26 @@ function main(conf) {
2322

2423
var message;
2524
var encoding;
26-
switch (conf.type) {
25+
switch (type) {
2726
case 'asc':
28-
message = 'a'.repeat(conf.len);
27+
message = 'a'.repeat(len);
2928
encoding = 'ascii';
3029
break;
3130
case 'utf':
32-
message = 'ü'.repeat(conf.len / 2);
31+
message = 'ü'.repeat(len / 2);
3332
encoding = 'utf8';
3433
break;
3534
case 'buf':
36-
message = Buffer.alloc(conf.len, 'b');
35+
message = Buffer.alloc(len, 'b');
3736
break;
3837
default:
39-
throw new Error(`unknown message type: ${conf.type}`);
38+
throw new Error(`unknown message type: ${type}`);
4039
}
4140

4241
const fn = api === 'stream' ? streamWrite : legacyWrite;
4342

4443
bench.start();
45-
fn(conf.algo, message, encoding, conf.writes, conf.len, conf.out);
44+
fn(algo, message, encoding, writes, len, out);
4645
}
4746

4847
function legacyWrite(algo, message, encoding, writes, len, outEnc) {
Collapse file

‎benchmark/crypto/hash-stream-throughput.js‎

Copy file name to clipboardExpand all lines: benchmark/crypto/hash-stream-throughput.js
+7-8Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ const bench = common.createBenchmark(main, {
1212
api: ['legacy', 'stream']
1313
});
1414

15-
function main(conf) {
16-
var api = conf.api;
15+
function main({ api, type, len, algo, writes }) {
1716
if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) {
1817
console.error('Crypto streams not available until v0.10');
1918
// use the legacy, just so that we can compare them.
@@ -22,26 +21,26 @@ function main(conf) {
2221

2322
var message;
2423
var encoding;
25-
switch (conf.type) {
24+
switch (type) {
2625
case 'asc':
27-
message = 'a'.repeat(conf.len);
26+
message = 'a'.repeat(len);
2827
encoding = 'ascii';
2928
break;
3029
case 'utf':
31-
message = 'ü'.repeat(conf.len / 2);
30+
message = 'ü'.repeat(len / 2);
3231
encoding = 'utf8';
3332
break;
3433
case 'buf':
35-
message = Buffer.alloc(conf.len, 'b');
34+
message = Buffer.alloc(len, 'b');
3635
break;
3736
default:
38-
throw new Error(`unknown message type: ${conf.type}`);
37+
throw new Error(`unknown message type: ${type}`);
3938
}
4039

4140
const fn = api === 'stream' ? streamWrite : legacyWrite;
4241

4342
bench.start();
44-
fn(conf.algo, message, encoding, conf.writes, conf.len);
43+
fn(algo, message, encoding, writes, len);
4544
}
4645

4746
function legacyWrite(algo, message, encoding, writes, len) {
Collapse file

‎benchmark/crypto/rsa-encrypt-decrypt-throughput.js‎

Copy file name to clipboardExpand all lines: benchmark/crypto/rsa-encrypt-decrypt-throughput.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ const bench = common.createBenchmark(main, {
2222
len: [16, 32, 64]
2323
});
2424

25-
function main(conf) {
26-
const message = Buffer.alloc(conf.len, 'b');
25+
function main({ len, algo, keylen, n }) {
26+
const message = Buffer.alloc(len, 'b');
2727
bench.start();
28-
StreamWrite(conf.algo, conf.keylen, message, conf.n, conf.len);
28+
StreamWrite(algo, keylen, message, n, len);
2929
}
3030

3131
function StreamWrite(algo, keylen, message, n, len) {
Collapse file

‎benchmark/crypto/rsa-sign-verify-throughput.js‎

Copy file name to clipboardExpand all lines: benchmark/crypto/rsa-sign-verify-throughput.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ const bench = common.createBenchmark(main, {
2323
len: [1024, 102400, 2 * 102400, 3 * 102400, 1024 * 1024]
2424
});
2525

26-
function main(conf) {
27-
const message = Buffer.alloc(conf.len, 'b');
26+
function main({ len, algo, keylen, writes }) {
27+
const message = Buffer.alloc(len, 'b');
2828
bench.start();
29-
StreamWrite(conf.algo, conf.keylen, message, conf.writes, conf.len);
29+
StreamWrite(algo, keylen, message, writes, len);
3030
}
3131

3232
function StreamWrite(algo, keylen, message, writes, len) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.