Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: add benchmarks for the test_runner #48931

Merged
merged 9 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
},
});
40 changes: 40 additions & 0 deletions benchmark/test_runner/global-concurrent-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'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);
switch (type) {
case 'sync':{
for (let i = 0; i < n; i++) {
promises[i] = it(`${i}`, () => {
});
}
break;
}

case 'async':
for (let i = 0; i < n; i++) {
promises[i] = it(`${i}`, async () => {
});
rluvaton marked this conversation as resolved.
Show resolved Hide resolved
}
break;
}

await Promise.all(promises);
}

function main({ n, type }) {
bench.start();
run(n, type).then(() => {
bench.end(n);
});
}
41 changes: 41 additions & 0 deletions benchmark/test_runner/global-sequential-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'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);
switch (type) {
case 'sync':{
for (let i = 0; i < n; i++) {
await it(`${i}`, () => {
});
}
break;
}

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

await Promise.all(promises);
}

function main({ n }) {
bench.start();
run(n).then(() => {
bench.end(n);
});
}
60 changes: 60 additions & 0 deletions benchmark/test_runner/suite-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'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';

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

break;
}

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

break;
}
}

await finished(reporter);

return numberOfSuites * testsPerSuite;
}

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