Skip to content

Commit

Permalink
benchmark: add benchmarks for the test_runner
Browse files Browse the repository at this point in the history
PR-URL: nodejs#48931
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
Reviewed-By: Debadree Chatterjee <[email protected]>
  • Loading branch information
rluvaton authored and UlisesGascon committed Aug 14, 2023
1 parent 3f9b679 commit 63d2466
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 0 deletions.
8 changes: 8 additions & 0 deletions benchmark/fixtures/empty-test-reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { PassThrough } = require('node:stream');

module.exports = new PassThrough({
objectMode: true,
transform(chunk, encoding, callback) {
callback(null)
},
});
46 changes: 46 additions & 0 deletions benchmark/test_runner/global-concurrent-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';
const common = require('../common');
const { it } = require('node:test');

const bench = common.createBenchmark(main, {
n: [100, 1000, 1e4],
type: ['sync', 'async'],
}, {
// We don't want to test the reporter here
flags: ['--test-reporter=./benchmark/fixtures/empty-test-reporter.js'],
});

async function run(n, type) {
const promises = new Array(n);

// eslint-disable-next-line no-unused-vars
let avoidV8Optimization;

switch (type) {
case 'sync': {
for (let i = 0; i < n; i++) {
promises[i] = it(`${i}`, () => {
avoidV8Optimization = i;
});
}
break;
}

case 'async':
for (let i = 0; i < n; i++) {
promises[i] = it(`${i}`, async () => {
avoidV8Optimization = i;
});
}
break;
}

await Promise.all(promises);
}

function main({ n, type }) {
bench.start();
run(n, type).then(() => {
bench.end(n);
});
}
46 changes: 46 additions & 0 deletions benchmark/test_runner/global-sequential-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';
const common = require('../common');
const { it } = require('node:test');


const bench = common.createBenchmark(main, {
n: [100, 1000, 1e4],
type: ['sync', 'async'],
}, {
// We don't want to test the reporter here
flags: ['--test-reporter=./benchmark/fixtures/empty-test-reporter.js'],
});

async function run(n, type) {
// eslint-disable-next-line no-unused-vars
let avoidV8Optimization;

const promises = new Array(n);
switch (type) {
case 'sync': {
for (let i = 0; i < n; i++) {
await it(`${i}`, () => {
avoidV8Optimization = i;
});
}
break;
}

case 'async':
for (let i = 0; i < n; i++) {
await it(`${i}`, async () => {
avoidV8Optimization = i;
});
}
break;
}

await Promise.all(promises);
}

function main({ n }) {
bench.start();
run(n).then(() => {
bench.end(n);
});
}
65 changes: 65 additions & 0 deletions benchmark/test_runner/suite-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use strict';
const common = require('../common');
const { finished } = require('node:stream/promises');

const reporter = require('../fixtures/empty-test-reporter');

const { describe, it } = require('node:test');

const bench = common.createBenchmark(main, {
numberOfSuites: [10, 100],
testsPerSuite: [10, 100, 1000],
testType: ['sync', 'async'],
concurrency: ['yes', 'no'],
}, {
// We don't want to test the reporter here
flags: ['--test-reporter=./benchmark/fixtures/empty-test-reporter.js'],
});

async function run({ numberOfSuites, testsPerSuite, testType, concurrency }) {
concurrency = concurrency === 'yes';

// eslint-disable-next-line no-unused-vars
let avoidV8Optimization;

switch (testType) {
case 'sync': {
for (let i = 0; i < numberOfSuites; i++) {
describe(`${i}`, { concurrency }, () => {
for (let j = 0; j < testsPerSuite; j++) {
it(`${j}`, () => {
avoidV8Optimization = i;
});
}
});
}

break;
}

case 'async': {
for (let i = 0; i < numberOfSuites; i++) {
describe(`${i}`, { concurrency }, () => {
for (let j = 0; j < testsPerSuite; j++) {
it(`${j}`, async () => {
avoidV8Optimization = i;
});
}
});
}

break;
}
}

await finished(reporter);

return numberOfSuites * testsPerSuite;
}

function main(params) {
bench.start();
run(params).then((ops) => {
bench.end(ops);
});
}

0 comments on commit 63d2466

Please sign in to comment.