| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,13 +8,13 @@ const bench = common.createBenchmark(main, { | |||
| 8 | 8 | len: [1024, 4 * 1024, 16 * 1024, 64 * 1024, 256 * 1024, 1024 * 1024] | |
| 9 | 9 | }); | |
| 10 | 10 | ||
| 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]); | ||
| 14 | 14 | const iv = crypto.randomBytes(12); | |
| 15 | 15 | const associate_data = Buffer.alloc(16, 'z'); | |
| 16 | 16 | 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); | ||
| 18 | 18 | } | |
| 19 | 19 | ||
| 20 | 20 | function AEAD_Bench(cipher, message, associate_data, key, iv, n, len) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,8 +9,7 @@ const bench = common.createBenchmark(main, { | |||
| 9 | 9 | api: ['legacy', 'stream'] | |
| 10 | 10 | }); | |
| 11 | 11 | ||
| 12 | - function main(conf) { | ||
| 13 | - var api = conf.api; | ||
| 12 | + function main({ api, cipher, type, len, writes }) { | ||
| 14 | 13 | if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) { | |
| 15 | 14 | console.error('Crypto streams not available until v0.10'); | |
| 16 | 15 | // use the legacy, just so that we can compare them. | |
@@ -33,33 +32,33 @@ function main(conf) { | |||
| 33 | 32 | // alice_secret and bob_secret should be the same | |
| 34 | 33 | assert(alice_secret === bob_secret); | |
| 35 | 34 | ||
| 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); | ||
| 38 | 37 | ||
| 39 | 38 | var message; | |
| 40 | 39 | var encoding; | |
| 41 | - switch (conf.type) { | ||
| 40 | + switch (type) { | ||
| 42 | 41 | case 'asc': | |
| 43 | - message = 'a'.repeat(conf.len); | ||
| 42 | + message = 'a'.repeat(len); | ||
| 44 | 43 | encoding = 'ascii'; | |
| 45 | 44 | break; | |
| 46 | 45 | case 'utf': | |
| 47 | - message = 'ü'.repeat(conf.len / 2); | ||
| 46 | + message = 'ü'.repeat(len / 2); | ||
| 48 | 47 | encoding = 'utf8'; | |
| 49 | 48 | break; | |
| 50 | 49 | case 'buf': | |
| 51 | - message = Buffer.alloc(conf.len, 'b'); | ||
| 50 | + message = Buffer.alloc(len, 'b'); | ||
| 52 | 51 | break; | |
| 53 | 52 | default: | |
| 54 | - throw new Error(`unknown message type: ${conf.type}`); | ||
| 53 | + throw new Error(`unknown message type: ${type}`); | ||
| 55 | 54 | } | |
| 56 | 55 | ||
| 57 | 56 | const fn = api === 'stream' ? streamWrite : legacyWrite; | |
| 58 | 57 | ||
| 59 | 58 | // write data as fast as possible to alice, and have bob decrypt. | |
| 60 | 59 | // use old API for comparison to v0.8 | |
| 61 | 60 | bench.start(); | |
| 62 | - fn(alice_cipher, bob_cipher, message, encoding, conf.writes); | ||
| 61 | + fn(alice_cipher, bob_cipher, message, encoding, writes); | ||
| 63 | 62 | } | |
| 64 | 63 | ||
| 65 | 64 | function streamWrite(alice, bob, message, encoding, writes) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,12 +7,10 @@ const bench = common.createBenchmark(main, { | |||
| 7 | 7 | v: ['crypto', 'tls'] | |
| 8 | 8 | }); | |
| 9 | 9 | ||
| 10 | - function main(conf) { | ||
| 11 | - const n = +conf.n; | ||
| 12 | - const v = conf.v; | ||
| 10 | + function main({ n, v }) { | ||
| 13 | 11 | const method = require(v).getCiphers; | |
| 14 | 12 | var i = 0; | |
| 15 | - // first call to getChipers will dominate the results | ||
| 13 | + // First call to getChipers will dominate the results | ||
| 16 | 14 | if (n > 1) { | |
| 17 | 15 | for (; i < n; i++) | |
| 18 | 16 | method(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,8 +13,7 @@ const bench = common.createBenchmark(main, { | |||
| 13 | 13 | api: ['legacy', 'stream'] | |
| 14 | 14 | }); | |
| 15 | 15 | ||
| 16 | - function main(conf) { | ||
| 17 | - var api = conf.api; | ||
| 16 | + function main({ api, type, len, out, writes, algo }) { | ||
| 18 | 17 | if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) { | |
| 19 | 18 | console.error('Crypto streams not available until v0.10'); | |
| 20 | 19 | // use the legacy, just so that we can compare them. | |
@@ -23,26 +22,26 @@ function main(conf) { | |||
| 23 | 22 | ||
| 24 | 23 | var message; | |
| 25 | 24 | var encoding; | |
| 26 | - switch (conf.type) { | ||
| 25 | + switch (type) { | ||
| 27 | 26 | case 'asc': | |
| 28 | - message = 'a'.repeat(conf.len); | ||
| 27 | + message = 'a'.repeat(len); | ||
| 29 | 28 | encoding = 'ascii'; | |
| 30 | 29 | break; | |
| 31 | 30 | case 'utf': | |
| 32 | - message = 'ü'.repeat(conf.len / 2); | ||
| 31 | + message = 'ü'.repeat(len / 2); | ||
| 33 | 32 | encoding = 'utf8'; | |
| 34 | 33 | break; | |
| 35 | 34 | case 'buf': | |
| 36 | - message = Buffer.alloc(conf.len, 'b'); | ||
| 35 | + message = Buffer.alloc(len, 'b'); | ||
| 37 | 36 | break; | |
| 38 | 37 | default: | |
| 39 | - throw new Error(`unknown message type: ${conf.type}`); | ||
| 38 | + throw new Error(`unknown message type: ${type}`); | ||
| 40 | 39 | } | |
| 41 | 40 | ||
| 42 | 41 | const fn = api === 'stream' ? streamWrite : legacyWrite; | |
| 43 | 42 | ||
| 44 | 43 | bench.start(); | |
| 45 | - fn(conf.algo, message, encoding, conf.writes, conf.len, conf.out); | ||
| 44 | + fn(algo, message, encoding, writes, len, out); | ||
| 46 | 45 | } | |
| 47 | 46 | ||
| 48 | 47 | function legacyWrite(algo, message, encoding, writes, len, outEnc) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,8 +12,7 @@ const bench = common.createBenchmark(main, { | |||
| 12 | 12 | api: ['legacy', 'stream'] | |
| 13 | 13 | }); | |
| 14 | 14 | ||
| 15 | - function main(conf) { | ||
| 16 | - var api = conf.api; | ||
| 15 | + function main({ api, type, len, algo, writes }) { | ||
| 17 | 16 | if (api === 'stream' && /^v0\.[0-8]\./.test(process.version)) { | |
| 18 | 17 | console.error('Crypto streams not available until v0.10'); | |
| 19 | 18 | // use the legacy, just so that we can compare them. | |
@@ -22,26 +21,26 @@ function main(conf) { | |||
| 22 | 21 | ||
| 23 | 22 | var message; | |
| 24 | 23 | var encoding; | |
| 25 | - switch (conf.type) { | ||
| 24 | + switch (type) { | ||
| 26 | 25 | case 'asc': | |
| 27 | - message = 'a'.repeat(conf.len); | ||
| 26 | + message = 'a'.repeat(len); | ||
| 28 | 27 | encoding = 'ascii'; | |
| 29 | 28 | break; | |
| 30 | 29 | case 'utf': | |
| 31 | - message = 'ü'.repeat(conf.len / 2); | ||
| 30 | + message = 'ü'.repeat(len / 2); | ||
| 32 | 31 | encoding = 'utf8'; | |
| 33 | 32 | break; | |
| 34 | 33 | case 'buf': | |
| 35 | - message = Buffer.alloc(conf.len, 'b'); | ||
| 34 | + message = Buffer.alloc(len, 'b'); | ||
| 36 | 35 | break; | |
| 37 | 36 | default: | |
| 38 | - throw new Error(`unknown message type: ${conf.type}`); | ||
| 37 | + throw new Error(`unknown message type: ${type}`); | ||
| 39 | 38 | } | |
| 40 | 39 | ||
| 41 | 40 | const fn = api === 'stream' ? streamWrite : legacyWrite; | |
| 42 | 41 | ||
| 43 | 42 | bench.start(); | |
| 44 | - fn(conf.algo, message, encoding, conf.writes, conf.len); | ||
| 43 | + fn(algo, message, encoding, writes, len); | ||
| 45 | 44 | } | |
| 46 | 45 | ||
| 47 | 46 | function legacyWrite(algo, message, encoding, writes, len) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,10 +22,10 @@ const bench = common.createBenchmark(main, { | |||
| 22 | 22 | len: [16, 32, 64] | |
| 23 | 23 | }); | |
| 24 | 24 | ||
| 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'); | ||
| 27 | 27 | bench.start(); | |
| 28 | - StreamWrite(conf.algo, conf.keylen, message, conf.n, conf.len); | ||
| 28 | + StreamWrite(algo, keylen, message, n, len); | ||
| 29 | 29 | } | |
| 30 | 30 | ||
| 31 | 31 | function StreamWrite(algo, keylen, message, n, len) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,10 +23,10 @@ const bench = common.createBenchmark(main, { | |||
| 23 | 23 | len: [1024, 102400, 2 * 102400, 3 * 102400, 1024 * 1024] | |
| 24 | 24 | }); | |
| 25 | 25 | ||
| 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'); | ||
| 28 | 28 | bench.start(); | |
| 29 | - StreamWrite(conf.algo, conf.keylen, message, conf.writes, conf.len); | ||
| 29 | + StreamWrite(algo, keylen, message, writes, len); | ||
| 30 | 30 | } | |
| 31 | 31 | ||
| 32 | 32 | function StreamWrite(algo, keylen, message, writes, len) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments