Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: add some assert benchmarks #54734

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
benchmark: add throws and doesNotThrow bench
  • Loading branch information
RafaelGSS committed Sep 3, 2024
commit c81456822cd1892cf4f0ccc2118cc63ec3f967ee
27 changes: 27 additions & 0 deletions benchmark/assert/throws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const common = require('../common.js');
const assert = require('assert');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const assert = require('assert');
const assert = require('node:assert');


const bench = common.createBenchmark(main, {
n: [25, 2e5],
method: ['throws', 'doesNotThrow'],
});

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);
}