1'use strict'; 2const common = require('../common'); 3const { it } = require('node:test'); 4 5 6const bench = common.createBenchmark(main, { 7 n: [100, 1000, 1e4], 8 type: ['sync', 'async'], 9}, { 10 // We don't want to test the reporter here 11 flags: ['--test-reporter=./benchmark/fixtures/empty-test-reporter.js'], 12}); 13 14async function run(n, type) { 15 // eslint-disable-next-line no-unused-vars 16 let avoidV8Optimization; 17 18 const promises = new Array(n); 19 switch (type) { 20 case 'sync': { 21 for (let i = 0; i < n; i++) { 22 await it(`${i}`, () => { 23 avoidV8Optimization = i; 24 }); 25 } 26 break; 27 } 28 29 case 'async': 30 for (let i = 0; i < n; i++) { 31 await it(`${i}`, async () => { 32 avoidV8Optimization = i; 33 }); 34 } 35 break; 36 } 37 38 await Promise.all(promises); 39} 40 41function main({ n }) { 42 bench.start(); 43 run(n).then(() => { 44 bench.end(n); 45 }); 46} 47