summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-01-23 13:17:56 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-02-01 10:49:00 +0100
commit39ae0b98009e8d235ee7c6d885fd9702a49949ee (patch)
treedca144507b584305d6da54ae6f8fec36e9981da8 /benchmark
parent794e489eeadbe40fec7928ed9b8f25d7019d795e (diff)
downloadandroid-node-v8-39ae0b98009e8d235ee7c6d885fd9702a49949ee.tar.gz
android-node-v8-39ae0b98009e8d235ee7c6d885fd9702a49949ee.tar.bz2
android-node-v8-39ae0b98009e8d235ee7c6d885fd9702a49949ee.zip
benchmark: (crypto) refactor
PR-URL: https://github.com/nodejs/node/pull/18320 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/crypto/aes-gcm-throughput.js8
-rw-r--r--benchmark/crypto/cipher-stream.js19
-rw-r--r--benchmark/crypto/get-ciphers.js6
-rw-r--r--benchmark/crypto/hash-stream-creation.js15
-rw-r--r--benchmark/crypto/hash-stream-throughput.js15
-rw-r--r--benchmark/crypto/rsa-encrypt-decrypt-throughput.js6
-rw-r--r--benchmark/crypto/rsa-sign-verify-throughput.js6
7 files changed, 35 insertions, 40 deletions
diff --git a/benchmark/crypto/aes-gcm-throughput.js b/benchmark/crypto/aes-gcm-throughput.js
index 246455de78..5c1e71e728 100644
--- a/benchmark/crypto/aes-gcm-throughput.js
+++ b/benchmark/crypto/aes-gcm-throughput.js
@@ -8,13 +8,13 @@ const bench = common.createBenchmark(main, {
len: [1024, 4 * 1024, 16 * 1024, 64 * 1024, 256 * 1024, 1024 * 1024]
});
-function main(conf) {
- const message = Buffer.alloc(conf.len, 'b');
- const key = crypto.randomBytes(keylen[conf.cipher]);
+function main({ n, len, cipher }) {
+ const message = Buffer.alloc(len, 'b');
+ const key = crypto.randomBytes(keylen[cipher]);
const iv = crypto.randomBytes(12);
const associate_data = Buffer.alloc(16, 'z');
bench.start();
- AEAD_Bench(conf.cipher, message, associate_data, key, iv, conf.n, conf.len);
+ AEAD_Bench(cipher, message, associate_data, key, iv, n, len);
}
function AEAD_Bench(cipher, message, associate_data, key, iv, n, len) {
diff --git a/benchmark/crypto/cipher-stream.js b/benchmark/crypto/cipher-stream.js
index ca36bd736d..64f6ff7b72 100644
--- a/benchmark/crypto/cipher-stream.js
+++ b/benchmark/crypto/cipher-stream.js
@@ -9,8 +9,7 @@ const bench = common.createBenchmark(main, {
api: ['legacy', 'stream']
});
-function main(conf) {
- var api = conf.api;
+function main({ api, cipher, type, len, writes }) {
if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) {
console.error('Crypto streams not available until v0.10');
// use the legacy, just so that we can compare them.
@@ -33,25 +32,25 @@ function main(conf) {
// alice_secret and bob_secret should be the same
assert(alice_secret === bob_secret);
- const alice_cipher = crypto.createCipher(conf.cipher, alice_secret);
- const bob_cipher = crypto.createDecipher(conf.cipher, bob_secret);
+ const alice_cipher = crypto.createCipher(cipher, alice_secret);
+ const bob_cipher = crypto.createDecipher(cipher, bob_secret);
var message;
var encoding;
- switch (conf.type) {
+ switch (type) {
case 'asc':
- message = 'a'.repeat(conf.len);
+ message = 'a'.repeat(len);
encoding = 'ascii';
break;
case 'utf':
- message = 'ü'.repeat(conf.len / 2);
+ message = 'ü'.repeat(len / 2);
encoding = 'utf8';
break;
case 'buf':
- message = Buffer.alloc(conf.len, 'b');
+ message = Buffer.alloc(len, 'b');
break;
default:
- throw new Error(`unknown message type: ${conf.type}`);
+ throw new Error(`unknown message type: ${type}`);
}
const fn = api === 'stream' ? streamWrite : legacyWrite;
@@ -59,7 +58,7 @@ function main(conf) {
// write data as fast as possible to alice, and have bob decrypt.
// use old API for comparison to v0.8
bench.start();
- fn(alice_cipher, bob_cipher, message, encoding, conf.writes);
+ fn(alice_cipher, bob_cipher, message, encoding, writes);
}
function streamWrite(alice, bob, message, encoding, writes) {
diff --git a/benchmark/crypto/get-ciphers.js b/benchmark/crypto/get-ciphers.js
index 3f5ad17ad3..d4c10a2427 100644
--- a/benchmark/crypto/get-ciphers.js
+++ b/benchmark/crypto/get-ciphers.js
@@ -7,12 +7,10 @@ const bench = common.createBenchmark(main, {
v: ['crypto', 'tls']
});
-function main(conf) {
- const n = +conf.n;
- const v = conf.v;
+function main({ n, v }) {
const method = require(v).getCiphers;
var i = 0;
- // first call to getChipers will dominate the results
+ // First call to getChipers will dominate the results
if (n > 1) {
for (; i < n; i++)
method();
diff --git a/benchmark/crypto/hash-stream-creation.js b/benchmark/crypto/hash-stream-creation.js
index 5ac5a4f70b..faaa12a9e5 100644
--- a/benchmark/crypto/hash-stream-creation.js
+++ b/benchmark/crypto/hash-stream-creation.js
@@ -13,8 +13,7 @@ const bench = common.createBenchmark(main, {
api: ['legacy', 'stream']
});
-function main(conf) {
- var api = conf.api;
+function main({ api, type, len, out, writes, algo }) {
if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) {
console.error('Crypto streams not available until v0.10');
// use the legacy, just so that we can compare them.
@@ -23,26 +22,26 @@ function main(conf) {
var message;
var encoding;
- switch (conf.type) {
+ switch (type) {
case 'asc':
- message = 'a'.repeat(conf.len);
+ message = 'a'.repeat(len);
encoding = 'ascii';
break;
case 'utf':
- message = 'ü'.repeat(conf.len / 2);
+ message = 'ü'.repeat(len / 2);
encoding = 'utf8';
break;
case 'buf':
- message = Buffer.alloc(conf.len, 'b');
+ message = Buffer.alloc(len, 'b');
break;
default:
- throw new Error(`unknown message type: ${conf.type}`);
+ throw new Error(`unknown message type: ${type}`);
}
const fn = api === 'stream' ? streamWrite : legacyWrite;
bench.start();
- fn(conf.algo, message, encoding, conf.writes, conf.len, conf.out);
+ fn(algo, message, encoding, writes, len, out);
}
function legacyWrite(algo, message, encoding, writes, len, outEnc) {
diff --git a/benchmark/crypto/hash-stream-throughput.js b/benchmark/crypto/hash-stream-throughput.js
index 21ec3c7902..934e7a0b11 100644
--- a/benchmark/crypto/hash-stream-throughput.js
+++ b/benchmark/crypto/hash-stream-throughput.js
@@ -12,8 +12,7 @@ const bench = common.createBenchmark(main, {
api: ['legacy', 'stream']
});
-function main(conf) {
- var api = conf.api;
+function main({ api, type, len, algo, writes }) {
if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) {
console.error('Crypto streams not available until v0.10');
// use the legacy, just so that we can compare them.
@@ -22,26 +21,26 @@ function main(conf) {
var message;
var encoding;
- switch (conf.type) {
+ switch (type) {
case 'asc':
- message = 'a'.repeat(conf.len);
+ message = 'a'.repeat(len);
encoding = 'ascii';
break;
case 'utf':
- message = 'ü'.repeat(conf.len / 2);
+ message = 'ü'.repeat(len / 2);
encoding = 'utf8';
break;
case 'buf':
- message = Buffer.alloc(conf.len, 'b');
+ message = Buffer.alloc(len, 'b');
break;
default:
- throw new Error(`unknown message type: ${conf.type}`);
+ throw new Error(`unknown message type: ${type}`);
}
const fn = api === 'stream' ? streamWrite : legacyWrite;
bench.start();
- fn(conf.algo, message, encoding, conf.writes, conf.len);
+ fn(algo, message, encoding, writes, len);
}
function legacyWrite(algo, message, encoding, writes, len) {
diff --git a/benchmark/crypto/rsa-encrypt-decrypt-throughput.js b/benchmark/crypto/rsa-encrypt-decrypt-throughput.js
index edab5ae08f..40b69c31f9 100644
--- a/benchmark/crypto/rsa-encrypt-decrypt-throughput.js
+++ b/benchmark/crypto/rsa-encrypt-decrypt-throughput.js
@@ -22,10 +22,10 @@ const bench = common.createBenchmark(main, {
len: [16, 32, 64]
});
-function main(conf) {
- const message = Buffer.alloc(conf.len, 'b');
+function main({ len, algo, keylen, n }) {
+ const message = Buffer.alloc(len, 'b');
bench.start();
- StreamWrite(conf.algo, conf.keylen, message, conf.n, conf.len);
+ StreamWrite(algo, keylen, message, n, len);
}
function StreamWrite(algo, keylen, message, n, len) {
diff --git a/benchmark/crypto/rsa-sign-verify-throughput.js b/benchmark/crypto/rsa-sign-verify-throughput.js
index bcde3a43d4..3a0373b57d 100644
--- a/benchmark/crypto/rsa-sign-verify-throughput.js
+++ b/benchmark/crypto/rsa-sign-verify-throughput.js
@@ -23,10 +23,10 @@ const bench = common.createBenchmark(main, {
len: [1024, 102400, 2 * 102400, 3 * 102400, 1024 * 1024]
});
-function main(conf) {
- const message = Buffer.alloc(conf.len, 'b');
+function main({ len, algo, keylen, writes }) {
+ const message = Buffer.alloc(len, 'b');
bench.start();
- StreamWrite(conf.algo, conf.keylen, message, conf.writes, conf.len);
+ StreamWrite(algo, keylen, message, writes, len);
}
function StreamWrite(algo, keylen, message, writes, len) {