11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common.js'); 41cb0ef41Sopenharmony_ciconst { throws, doesNotThrow } = require('assert'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 71cb0ef41Sopenharmony_ci n: [1e4], 81cb0ef41Sopenharmony_ci method: [ 'doesNotThrow', 'throws_TypeError', 'throws_RegExp' ], 91cb0ef41Sopenharmony_ci}); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_cifunction main({ n, method }) { 121cb0ef41Sopenharmony_ci const throwError = () => { throw new TypeError('foobar'); }; 131cb0ef41Sopenharmony_ci const doNotThrowError = () => { return 'foobar'; }; 141cb0ef41Sopenharmony_ci const regExp = /foobar/; 151cb0ef41Sopenharmony_ci const message = 'failure'; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci switch (method) { 181cb0ef41Sopenharmony_ci case 'doesNotThrow': 191cb0ef41Sopenharmony_ci bench.start(); 201cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) { 211cb0ef41Sopenharmony_ci doesNotThrow(doNotThrowError); 221cb0ef41Sopenharmony_ci } 231cb0ef41Sopenharmony_ci bench.end(n); 241cb0ef41Sopenharmony_ci break; 251cb0ef41Sopenharmony_ci case 'throws_TypeError': 261cb0ef41Sopenharmony_ci bench.start(); 271cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) { 281cb0ef41Sopenharmony_ci throws(throwError, TypeError, message); 291cb0ef41Sopenharmony_ci } 301cb0ef41Sopenharmony_ci bench.end(n); 311cb0ef41Sopenharmony_ci break; 321cb0ef41Sopenharmony_ci case 'throws_RegExp': 331cb0ef41Sopenharmony_ci bench.start(); 341cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) { 351cb0ef41Sopenharmony_ci throws(throwError, regExp, message); 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci bench.end(n); 381cb0ef41Sopenharmony_ci break; 391cb0ef41Sopenharmony_ci default: 401cb0ef41Sopenharmony_ci throw new Error(`Unsupported method ${method}`); 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci} 43