Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2020-09-09 01:19:02 +0300
committerTobias Nießen <tniessen@tnie.de>2021-04-03 16:37:53 +0300
commit5dae7d67589c908a1fe672b084838c1397d00e54 (patch)
treefb1d0cbc12ccf322b53d4c50390a3eed27c8be2f /benchmark
parentfae0320e7eabc3ad72ec06af0561e614ae1b66f9 (diff)
crypto: add buffering to randomInt
PR-URL: https://github.com/nodejs/node/pull/35110 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/crypto/randomInt.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/benchmark/crypto/randomInt.js b/benchmark/crypto/randomInt.js
new file mode 100644
index 00000000000..1f1dfa0160f
--- /dev/null
+++ b/benchmark/crypto/randomInt.js
@@ -0,0 +1,38 @@
+'use strict';
+
+const common = require('../common.js');
+const { randomInt } = require('crypto');
+
+const bench = common.createBenchmark(main, {
+ mode: ['sync', 'async-sequential', 'async-parallel'],
+ min: [-(2 ** 47) + 1, -10_000, -100],
+ max: [100, 10_000, 2 ** 47],
+ n: [1e3, 1e5]
+});
+
+function main({ mode, min, max, n }) {
+ if (mode === 'sync') {
+ bench.start();
+ for (let i = 0; i < n; i++)
+ randomInt(min, max);
+ bench.end(n);
+ } else if (mode === 'async-sequential') {
+ bench.start();
+ (function next(i) {
+ if (i === n)
+ return bench.end(n);
+ randomInt(min, max, () => {
+ next(i + 1);
+ });
+ })(0);
+ } else {
+ bench.start();
+ let done = 0;
+ for (let i = 0; i < n; i++) {
+ randomInt(min, max, () => {
+ if (++done === n)
+ bench.end(n);
+ });
+ }
+ }
+}