forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: nodejs#48905 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Rich Trott <rtrott@gmail.com>
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 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,59 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
const path = require('path'); | ||
const { spawnSync } = require('child_process'); | ||
|
||
function mockFiles(n, prefix = '/tmp') { | ||
const files = []; | ||
for (let i = 0; i < n; ++i) { | ||
files.push(prefix + '/file' + i + '.js'); | ||
} | ||
|
||
return files; | ||
} | ||
|
||
const bench = common.createBenchmark(main, { | ||
script: [ | ||
'test/fixtures/semicolon', | ||
], | ||
prefixPath: ['/tmp'], | ||
nFiles: [10, 100, 1000], | ||
count: [30], | ||
}); | ||
|
||
function spawnProcess(script, bench, state) { | ||
const cmd = process.execPath || process.argv[0]; | ||
while (state.finished < state.count) { | ||
const child = spawnSync(cmd, script); | ||
if (child.status !== 0) { | ||
console.log('---- STDOUT ----'); | ||
console.log(child.stdout.toString()); | ||
console.log('---- STDERR ----'); | ||
console.log(child.stderr.toString()); | ||
throw new Error(`Child process stopped with exit code ${child.status}`); | ||
} | ||
state.finished++; | ||
if (state.finished === 0) { | ||
// Finished warmup. | ||
bench.start(); | ||
} | ||
|
||
if (state.finished === state.count) { | ||
bench.end(state.count); | ||
} | ||
} | ||
} | ||
|
||
function main({ count, script, nFiles, prefixPath }) { | ||
script = path.resolve(__dirname, '../../', `${script}.js`); | ||
const files = mockFiles(nFiles, prefixPath).join(','); | ||
const optionsWithScript = [ | ||
'--experimental-permission', | ||
`--allow-fs-read=${files},${script}`, | ||
script, | ||
]; | ||
const warmup = 3; | ||
const state = { count, finished: -warmup }; | ||
spawnProcess(optionsWithScript, bench, state); | ||
} |