11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common.js'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 61cb0ef41Sopenharmony_ci type: ['hide-stackframes-throw', 'direct-call-throw', 71cb0ef41Sopenharmony_ci 'hide-stackframes-noerr', 'direct-call-noerr'], 81cb0ef41Sopenharmony_ci n: [10e4], 91cb0ef41Sopenharmony_ci}, { 101cb0ef41Sopenharmony_ci flags: ['--expose-internals'], 111cb0ef41Sopenharmony_ci}); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cifunction main({ n, type }) { 141cb0ef41Sopenharmony_ci const { 151cb0ef41Sopenharmony_ci hideStackFrames, 161cb0ef41Sopenharmony_ci codes: { 171cb0ef41Sopenharmony_ci ERR_INVALID_ARG_TYPE, 181cb0ef41Sopenharmony_ci }, 191cb0ef41Sopenharmony_ci } = require('internal/errors'); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci const testfn = (value) => { 221cb0ef41Sopenharmony_ci if (typeof value !== 'number') { 231cb0ef41Sopenharmony_ci throw new ERR_INVALID_ARG_TYPE('Benchmark', 'number', value); 241cb0ef41Sopenharmony_ci } 251cb0ef41Sopenharmony_ci }; 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci let fn = testfn; 281cb0ef41Sopenharmony_ci if (type.startsWith('hide-stackframe')) 291cb0ef41Sopenharmony_ci fn = hideStackFrames(testfn); 301cb0ef41Sopenharmony_ci let value = 42; 311cb0ef41Sopenharmony_ci if (type.endsWith('-throw')) 321cb0ef41Sopenharmony_ci value = 'err'; 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci bench.start(); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) { 371cb0ef41Sopenharmony_ci try { 381cb0ef41Sopenharmony_ci fn(value); 391cb0ef41Sopenharmony_ci } catch { 401cb0ef41Sopenharmony_ci // No-op 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci } 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci bench.end(n); 451cb0ef41Sopenharmony_ci} 46