11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst fs = require('fs'); 31cb0ef41Sopenharmony_ciconst path = require('path'); 41cb0ef41Sopenharmony_ciconst common = require('../common.js'); 51cb0ef41Sopenharmony_ciconst { strictEqual } = require('assert'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst tmpdir = require('../../test/common/tmpdir'); 81cb0ef41Sopenharmony_ciconst benchmarkDirectory = 91cb0ef41Sopenharmony_ci path.resolve(tmpdir.path, 'benchmark-esm-parse'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 121cb0ef41Sopenharmony_ci n: [1e2], 131cb0ef41Sopenharmony_ci}); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciasync function main({ n }) { 161cb0ef41Sopenharmony_ci tmpdir.refresh(); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci fs.mkdirSync(benchmarkDirectory); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci let sampleSource = 'try {\n'; 211cb0ef41Sopenharmony_ci for (let i = 0; i < 1000; i++) { 221cb0ef41Sopenharmony_ci sampleSource += 'sample.js(() => file = /test/);\n'; 231cb0ef41Sopenharmony_ci } 241cb0ef41Sopenharmony_ci sampleSource += '} catch {}\nexports.p = 5;\n'; 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) { 271cb0ef41Sopenharmony_ci const sampleFile = path.join(benchmarkDirectory, `sample${i}.js`); 281cb0ef41Sopenharmony_ci fs.writeFileSync(sampleFile, sampleSource); 291cb0ef41Sopenharmony_ci } 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci bench.start(); 321cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) { 331cb0ef41Sopenharmony_ci const sampleFile = path.join(benchmarkDirectory, `sample${i}.js`); 341cb0ef41Sopenharmony_ci const m = await import('file:' + sampleFile); 351cb0ef41Sopenharmony_ci strictEqual(m.p, 5); 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci bench.end(n); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci tmpdir.refresh(); 401cb0ef41Sopenharmony_ci} 41