| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,59 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + const path = require('path'); | ||
| 5 | + const { spawnSync } = require('child_process'); | ||
| 6 | + | ||
| 7 | + function mockFiles(n, prefix = '/tmp') { | ||
| 8 | + const files = []; | ||
| 9 | + for (let i = 0; i < n; ++i) { | ||
| 10 | + files.push(prefix + '/file' + i + '.js'); | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + return files; | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + const bench = common.createBenchmark(main, { | ||
| 17 | + script: [ | ||
| 18 | + 'test/fixtures/semicolon', | ||
| 19 | + ], | ||
| 20 | + prefixPath: ['/tmp'], | ||
| 21 | + nFiles: [10, 100, 1000], | ||
| 22 | + count: [30], | ||
| 23 | + }); | ||
| 24 | + | ||
| 25 | + function spawnProcess(script, bench, state) { | ||
| 26 | + const cmd = process.execPath || process.argv[0]; | ||
| 27 | + while (state.finished < state.count) { | ||
| 28 | + const child = spawnSync(cmd, script); | ||
| 29 | + if (child.status !== 0) { | ||
| 30 | + console.log('---- STDOUT ----'); | ||
| 31 | + console.log(child.stdout.toString()); | ||
| 32 | + console.log('---- STDERR ----'); | ||
| 33 | + console.log(child.stderr.toString()); | ||
| 34 | + throw new Error(`Child process stopped with exit code ${child.status}`); | ||
| 35 | + } | ||
| 36 | + state.finished++; | ||
| 37 | + if (state.finished === 0) { | ||
| 38 | + // Finished warmup. | ||
| 39 | + bench.start(); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + if (state.finished === state.count) { | ||
| 43 | + bench.end(state.count); | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + function main({ count, script, nFiles, prefixPath }) { | ||
| 49 | + script = path.resolve(__dirname, '../../', `${script}.js`); | ||
| 50 | + const files = mockFiles(nFiles, prefixPath).join(','); | ||
| 51 | + const optionsWithScript = [ | ||
| 52 | + '--experimental-permission', | ||
| 53 | + `--allow-fs-read=${files},${script}`, | ||
| 54 | + script, | ||
| 55 | + ]; | ||
| 56 | + const warmup = 3; | ||
| 57 | + const state = { count, finished: -warmup }; | ||
| 58 | + spawnProcess(optionsWithScript, bench, state); | ||
| 59 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments