Skip to content

Commit

Permalink
benchmark: add strictEqual and notStrictEqual bench
Browse files Browse the repository at this point in the history
PR-URL: #54734
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
  • Loading branch information
RafaelGSS authored and aduh95 committed Sep 12, 2024
1 parent 3981853 commit 456a1fe
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions benchmark/assert/strictequal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

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

const bench = common.createBenchmark(main, {
n: [25, 2e5],
type: ['string', 'object', 'number'],
method: ['strictEqual', 'notStrictEqual'],
});

function main({ type, n, method }) {
const fn = assert[method];
let actual, expected;
switch (type) {
case 'string':
actual = expected = 'Hello World';
if (method === 'notStrictEqual') {
expected += 'bar';
}
break;
case 'object':
actual = expected = { a: 'Hello', b: 'World' };
if (method === 'notStrictEqual') {
expected = { a: 'Hello', b: 'World' };
}
break;
case 'number':
actual = expected = 1e9;
if (method === 'notStrictEqual') {
expected += 1;
}
break;
default:
throw new Error('Unexpected type');
}

bench.start();
for (let i = 0; i < n; ++i) {
fn(actual, expected);
}
bench.end(n);
}

0 comments on commit 456a1fe

Please sign in to comment.