-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: fix and extend assert benchmarks
The benchmarks had the strict and non strict labels switched. This is fixed and the benchmarks were extended to check more possible input types and function calls. PR-URL: #14147 Refs: #13973 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
7 changed files
with
328 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
const assert = require('assert'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e6], | ||
size: [1e2, 1e3, 1e4], | ||
method: [ | ||
'deepEqual', | ||
'deepStrictEqual', | ||
'notDeepEqual', | ||
'notDeepStrictEqual' | ||
] | ||
}); | ||
|
||
function createObj(source, add = '') { | ||
return source.map((n) => ({ | ||
foo: 'yarp', | ||
nope: { | ||
bar: `123${add}`, | ||
a: [1, 2, 3], | ||
baz: n | ||
} | ||
})); | ||
} | ||
|
||
function main(conf) { | ||
const size = +conf.size; | ||
// TODO: Fix this "hack" | ||
const n = (+conf.n) / size; | ||
var i; | ||
|
||
const source = Array.apply(null, Array(size)); | ||
const actual = createObj(source); | ||
const expected = createObj(source); | ||
const expectedWrong = createObj(source, '4'); | ||
|
||
switch (conf.method) { | ||
case 'deepEqual': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
// eslint-disable-next-line no-restricted-properties | ||
assert.deepEqual(actual, expected); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'deepStrictEqual': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
assert.deepStrictEqual(actual, expected); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'notDeepEqual': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
// eslint-disable-next-line no-restricted-properties | ||
assert.notDeepEqual(actual, expectedWrong); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'notDeepStrictEqual': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
assert.notDeepStrictEqual(actual, expectedWrong); | ||
} | ||
bench.end(n); | ||
break; | ||
default: | ||
throw new Error('Unsupported method'); | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
benchmark/assert/deepequal-prims-and-objs-big-array-set.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
const assert = require('assert'); | ||
|
||
const primValues = { | ||
'null': null, | ||
'undefined': undefined, | ||
'string': 'a', | ||
'number': 1, | ||
'boolean': true, | ||
'object': { 0: 'a' }, | ||
'array': [1, 2, 3], | ||
'new-array': new Array([1, 2, 3]) | ||
}; | ||
|
||
const bench = common.createBenchmark(main, { | ||
prim: Object.keys(primValues), | ||
n: [25], | ||
len: [1e5], | ||
method: [ | ||
'deepEqual_Array', | ||
'deepStrictEqual_Array', | ||
'notDeepEqual_Array', | ||
'notDeepStrictEqual_Array', | ||
'deepEqual_Set', | ||
'deepStrictEqual_Set', | ||
'notDeepEqual_Set', | ||
'notDeepStrictEqual_Set' | ||
] | ||
}); | ||
|
||
function main(conf) { | ||
const prim = primValues[conf.prim]; | ||
const n = +conf.n; | ||
const len = +conf.len; | ||
const actual = []; | ||
const expected = []; | ||
const expectedWrong = []; | ||
var i; | ||
|
||
for (var x = 0; x < len; x++) { | ||
actual.push(prim); | ||
expected.push(prim); | ||
expectedWrong.push(prim); | ||
} | ||
expectedWrong.pop(); | ||
expectedWrong.push('b'); | ||
|
||
// Note: primitives are only added once to a set | ||
const actualSet = new Set(actual); | ||
const expectedSet = new Set(expected); | ||
const expectedWrongSet = new Set(expectedWrong); | ||
|
||
switch (conf.method) { | ||
case 'deepEqual_Array': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
// eslint-disable-next-line no-restricted-properties | ||
assert.deepEqual(actual, expected); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'deepStrictEqual_Array': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
assert.deepStrictEqual(actual, expected); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'notDeepEqual_Array': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
// eslint-disable-next-line no-restricted-properties | ||
assert.notDeepEqual(actual, expectedWrong); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'notDeepStrictEqual_Array': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
assert.notDeepStrictEqual(actual, expectedWrong); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'deepEqual_Set': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
// eslint-disable-next-line no-restricted-properties | ||
assert.deepEqual(actualSet, expectedSet); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'deepStrictEqual_Set': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
assert.deepStrictEqual(actualSet, expectedSet); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'notDeepEqual_Set': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
// eslint-disable-next-line no-restricted-properties | ||
assert.notDeepEqual(actualSet, expectedWrongSet); | ||
} | ||
bench.end(n); | ||
break; | ||
case 'notDeepStrictEqual_Set': | ||
bench.start(); | ||
for (i = 0; i < n; ++i) { | ||
assert.notDeepStrictEqual(actualSet, expectedWrongSet); | ||
} | ||
bench.end(n); | ||
break; | ||
default: | ||
throw new Error('Unsupported method'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.