benchmark: add per-suite setup option · nodejs/node@b6114ae · GitHub
Skip to content

Commit b6114ae

Browse files
joyeecheungaduh95
authored andcommitted
benchmark: add per-suite setup option
This allows us to set up fixtures for the benchmark suite only once, which can save quite a bit of time when running benchmarks that require tens of thousands of fixture files or more (e.g. the module benchmarks). PR-URL: #60574 Fixes: #58488 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent ea71e96 commit b6114ae

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

benchmark/common.js

Lines changed: 7 additions & 0 deletions

benchmark/module/module-require.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ const benchmarkDirectory = tmpdir.resolve('nodejs-benchmark-module');
88
const bench = common.createBenchmark(main, {
99
type: ['.js', '.json', 'dir'],
1010
n: [1e4],
11+
}, {
12+
setup(configs) {
13+
tmpdir.refresh();
14+
const maxN = configs.reduce((max, c) => Math.max(max, c.n), 0);
15+
createEntryPoint(maxN);
16+
},
1117
});
1218

1319
function main({ type, n }) {
14-
tmpdir.refresh();
15-
createEntryPoint(n);
16-
1720
switch (type) {
1821
case '.js':
1922
measureJSFile(n);
@@ -24,8 +27,6 @@ function main({ type, n }) {
2427
case 'dir':
2528
measureDir(n);
2629
}
27-
28-
tmpdir.refresh();
2930
}
3031

3132
function measureJSFile(n) {

doc/contributing/writing-and-running-benchmarks.md

Lines changed: 26 additions & 0 deletions

0 commit comments

Comments
 (0)