Skip to content

Commit 8f10156

Browse files
RafaelGSStargos
authored andcommitted
benchmark: add strictEqual and notStrictEqual bench
PR-URL: #54734 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent a5984e4 commit 8f10156

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

benchmark/assert/strictequal.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const assert = require('assert');
5+
6+
const bench = common.createBenchmark(main, {
7+
n: [25, 2e5],
8+
type: ['string', 'object', 'number'],
9+
method: ['strictEqual', 'notStrictEqual'],
10+
});
11+
12+
function main({ type, n, method }) {
13+
const fn = assert[method];
14+
let actual, expected;
15+
switch (type) {
16+
case 'string':
17+
actual = expected = 'Hello World';
18+
if (method === 'notStrictEqual') {
19+
expected += 'bar';
20+
}
21+
break;
22+
case 'object':
23+
actual = expected = { a: 'Hello', b: 'World' };
24+
if (method === 'notStrictEqual') {
25+
expected = { a: 'Hello', b: 'World' };
26+
}
27+
break;
28+
case 'number':
29+
actual = expected = 1e9;
30+
if (method === 'notStrictEqual') {
31+
expected += 1;
32+
}
33+
break;
34+
default:
35+
throw new Error('Unexpected type');
36+
}
37+
38+
bench.start();
39+
for (let i = 0; i < n; ++i) {
40+
fn(actual, expected);
41+
}
42+
bench.end(n);
43+
}

0 commit comments

Comments
 (0)