summaryrefslogtreecommitdiff
path: root/benchmark/crypto/hkdf.js
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2020-08-25 10:05:51 -0700
committerJames M Snell <jasnell@gmail.com>2020-10-07 17:27:05 -0700
commitdae283d96fd31ad0f30840a7e55ac97294f505ac (patch)
tree8f7f87e50411e8965cb83d9b280035f36d355fbc /benchmark/crypto/hkdf.js
parentba77dc8597cbcf42feea59f1381512d421ec9cc5 (diff)
downloadnode-new-dae283d96fd31ad0f30840a7e55ac97294f505ac.tar.gz
crypto: refactoring internals, add WebCrypto
Fixes: https://github.com/nodejs/node/issues/678 Refs: https://github.com/nodejs/node/issues/26854 Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/35093 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'benchmark/crypto/hkdf.js')
-rw-r--r--benchmark/crypto/hkdf.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/benchmark/crypto/hkdf.js b/benchmark/crypto/hkdf.js
new file mode 100644
index 0000000000..4be15ab590
--- /dev/null
+++ b/benchmark/crypto/hkdf.js
@@ -0,0 +1,44 @@
+'use strict';
+
+const common = require('../common.js');
+const assert = require('assert');
+const {
+ hkdf,
+ hkdfSync
+} = require('crypto');
+
+const bench = common.createBenchmark(main, {
+ sync: [0, 1],
+ size: [10, 64, 1024],
+ key: ['a', 'secret', 'this-is-a-much-longer-secret'],
+ salt: ['', 'salt'],
+ info: ['', 'info'],
+ hash: ['sha256', 'sha512'],
+ n: [1e3],
+});
+
+function measureSync(n, size, salt, info, hash, key) {
+ bench.start();
+ for (let i = 0; i < n; ++i)
+ hkdfSync(hash, key, salt, info, size);
+ bench.end(n);
+}
+
+function measureAsync(n, size, salt, info, hash, key) {
+ let remaining = n;
+ function done(err) {
+ assert.ifError(err);
+ if (--remaining === 0)
+ bench.end(n);
+ }
+ bench.start();
+ for (let i = 0; i < n; ++i)
+ hkdf(hash, key, salt, info, size, done);
+}
+
+function main({ n, sync, size, salt, info, hash, key }) {
+ if (sync)
+ measureSync(n, size, salt, info, hash, key);
+ else
+ measureAsync(n, size, salt, info, hash, key);
+}