-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: #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>
- Loading branch information
Showing
2 changed files
with
100 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters