MCPcopy Index your code
hub / github.com/nodejs/node / runBenchmark

Function runBenchmark

test/common/benchmark.js:9–52  ·  view source on GitHub ↗
(name, env)

Source from the content-addressed store, hash-verified

7const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
8
9function runBenchmark(name, env) {
10 const argv = ['test'];
11
12 argv.push(name);
13
14 const mergedEnv = { ...process.env, ...env };
15
16 const child = fork(runjs, argv, {
17 env: mergedEnv,
18 stdio: ['inherit', 'pipe', 'inherit', 'ipc'],
19 });
20 child.stdout.setEncoding('utf8');
21
22 let stdout = '';
23 child.stdout.on('data', (line) => {
24 stdout += line;
25 });
26
27 child.on('exit', (code, signal) => {
28 assert.strictEqual(code, 0);
29 assert.strictEqual(signal, null);
30
31 // This bit makes sure that each benchmark file is being sent settings such
32 // that the benchmark file runs just one set of options. This helps keep the
33 // benchmark tests from taking a long time to run. Therefore, stdout should be composed as follows:
34 // The first and last lines should be empty.
35 // Each test should be separated by a blank line.
36 // The first line of each test should contain the test's name.
37 // The second line of each test should contain the configuration for the test.
38 // If the test configuration is not a group, there should be exactly two lines.
39 // Otherwise, it is possible to have more than two lines.
40
41 const splitTests = stdout.split(/\n\s*\n/);
42
43 for (let testIdx = 1; testIdx < splitTests.length - 1; testIdx++) {
44 const lines = splitTests[testIdx].split('\n');
45 assert.match(lines[0], /.+/);
46
47 if (!lines[1].includes('group="')) {
48 assert.strictEqual(lines.length, 2, `benchmark file not running exactly one configuration in test: ${stdout}`);
49 }
50 }
51 });
52}
53
54module.exports = runBenchmark;

Calls 7

includesMethod · 0.80
matchMethod · 0.65
forkFunction · 0.50
pushMethod · 0.45
setEncodingMethod · 0.45
onMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…