11cb0ef41Sopenharmony_ci// This benchmark is meant to exercise a grab bag of code paths that would 21cb0ef41Sopenharmony_ci// be expected to run slower under coverage. 31cb0ef41Sopenharmony_ci'use strict'; 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst common = require('../common.js'); 61cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 71cb0ef41Sopenharmony_ci n: [1e5], 81cb0ef41Sopenharmony_ci}); 91cb0ef41Sopenharmony_ciconst path = require('path'); 101cb0ef41Sopenharmony_ciconst { rmSync } = require('fs'); 111cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process'); 121cb0ef41Sopenharmony_ciconst tmpdir = require('../../test/common/tmpdir'); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciconst coverageDir = path.join(tmpdir.path, `./cov-${Date.now()}`); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_cifunction main({ n }) { 171cb0ef41Sopenharmony_ci bench.start(); 181cb0ef41Sopenharmony_ci const result = spawnSync(process.execPath, [ 191cb0ef41Sopenharmony_ci require.resolve('../fixtures/coverage-many-branches'), 201cb0ef41Sopenharmony_ci ], { 211cb0ef41Sopenharmony_ci env: { 221cb0ef41Sopenharmony_ci NODE_V8_COVERAGE: coverageDir, 231cb0ef41Sopenharmony_ci N: n, 241cb0ef41Sopenharmony_ci ...process.env, 251cb0ef41Sopenharmony_ci }, 261cb0ef41Sopenharmony_ci }); 271cb0ef41Sopenharmony_ci bench.end(n); 281cb0ef41Sopenharmony_ci rmSync(coverageDir, { recursive: true, force: true }); 291cb0ef41Sopenharmony_ci if (result.status !== 0) { 301cb0ef41Sopenharmony_ci throw new Error(result.stderr.toString('utf8')); 311cb0ef41Sopenharmony_ci } 321cb0ef41Sopenharmony_ci} 33