diff options
author | Tobias Nießen <tniessen@tnie.de> | 2020-09-09 00:19:02 +0200 |
---|---|---|
committer | Tobias Nießen <tniessen@tnie.de> | 2021-04-03 15:37:53 +0200 |
commit | 5dae7d67589c908a1fe672b084838c1397d00e54 (patch) | |
tree | fb1d0cbc12ccf322b53d4c50390a3eed27c8be2f /benchmark | |
parent | fae0320e7eabc3ad72ec06af0561e614ae1b66f9 (diff) | |
download | node-new-5dae7d67589c908a1fe672b084838c1397d00e54.tar.gz |
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.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/benchmark/crypto/randomInt.js b/benchmark/crypto/randomInt.js new file mode 100644 index 0000000000..1f1dfa0160 --- /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); + }); + } + } +} |