mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 13:40:37 +00:00

These benchmarks are not frequently needed and just slow down the default benchmark suite. They are kept for users who want to run them but deactivated by default. PR-URL: https://github.com/nodejs/node/pull/57370 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
34 lines
738 B
JavaScript
34 lines
738 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
const assert = require('assert');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
n: [2e5],
|
|
method: ['throws', 'doesNotThrow'],
|
|
}, {
|
|
combinationFilter(p) {
|
|
// These benchmarks purposefully do not run by default. They do not provide
|
|
// much insight, due to only being a small wrapper around a try / catch.
|
|
return p.n === 1;
|
|
},
|
|
});
|
|
|
|
function main({ n, method }) {
|
|
const fn = assert[method];
|
|
const shouldThrow = method === 'throws';
|
|
|
|
bench.start();
|
|
for (let i = 0; i < n; ++i) {
|
|
fn(() => {
|
|
const err = new Error(`assert.${method}`);
|
|
if (shouldThrow) {
|
|
throw err;
|
|
} else {
|
|
return err;
|
|
}
|
|
});
|
|
}
|
|
bench.end(n);
|
|
}
|