|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const { finished } = require('node:stream/promises'); |
| 4 | + |
| 5 | +const reporter = require('../fixtures/empty-test-reporter'); |
| 6 | + |
| 7 | +const { describe, it } = require('node:test'); |
| 8 | + |
| 9 | +const bench = common.createBenchmark(main, { |
| 10 | + numberOfSuites: [10, 100], |
| 11 | + testsPerSuite: [10, 100, 1000], |
| 12 | + testType: ['sync', 'async'], |
| 13 | + concurrency: ['yes', 'no'], |
| 14 | +}, { |
| 15 | + // We don't want to test the reporter here |
| 16 | + flags: ['--test-reporter=./benchmark/fixtures/empty-test-reporter.js'], |
| 17 | +}); |
| 18 | + |
| 19 | +async function run({ numberOfSuites, testsPerSuite, testType, concurrency }) { |
| 20 | + concurrency = concurrency === 'yes'; |
| 21 | + |
| 22 | + // eslint-disable-next-line no-unused-vars |
| 23 | + let avoidV8Optimization; |
| 24 | + |
| 25 | + switch (testType) { |
| 26 | + case 'sync': { |
| 27 | + for (let i = 0; i < numberOfSuites; i++) { |
| 28 | + describe(`${i}`, { concurrency }, () => { |
| 29 | + for (let j = 0; j < testsPerSuite; j++) { |
| 30 | + it(`${j}`, () => { |
| 31 | + avoidV8Optimization = i; |
| 32 | + }); |
| 33 | + } |
| 34 | + }); |
| 35 | + } |
| 36 | + |
| 37 | + break; |
| 38 | + } |
| 39 | + |
| 40 | + case 'async': { |
| 41 | + for (let i = 0; i < numberOfSuites; i++) { |
| 42 | + describe(`${i}`, { concurrency }, () => { |
| 43 | + for (let j = 0; j < testsPerSuite; j++) { |
| 44 | + it(`${j}`, async () => { |
| 45 | + avoidV8Optimization = i; |
| 46 | + }); |
| 47 | + } |
| 48 | + }); |
| 49 | + } |
| 50 | + |
| 51 | + break; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + await finished(reporter); |
| 56 | + |
| 57 | + return numberOfSuites * testsPerSuite; |
| 58 | +} |
| 59 | + |
| 60 | +function main(params) { |
| 61 | + bench.start(); |
| 62 | + run(params).then((ops) => { |
| 63 | + bench.end(ops); |
| 64 | + }); |
| 65 | +} |
0 commit comments