benchmark: (assert) use destructuring
PR-URL: https://github.com/nodejs/node/pull/18250 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
0beef3f030
commit
366fd03af0
@ -13,9 +13,7 @@ const bench = common.createBenchmark(main, {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
function main(conf) {
|
function main({ len, n, method }) {
|
||||||
const n = +conf.n;
|
|
||||||
const len = +conf.len;
|
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
const data = Buffer.allocUnsafe(len + 1);
|
const data = Buffer.allocUnsafe(len + 1);
|
||||||
@ -26,7 +24,7 @@ function main(conf) {
|
|||||||
data.copy(expected);
|
data.copy(expected);
|
||||||
data.copy(expectedWrong);
|
data.copy(expectedWrong);
|
||||||
|
|
||||||
switch (conf.method) {
|
switch (method) {
|
||||||
case '':
|
case '':
|
||||||
// Empty string falls through to next line as default, mostly for tests.
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'deepEqual':
|
case 'deepEqual':
|
||||||
|
@ -38,14 +38,11 @@ function benchmark(method, n, values, values2) {
|
|||||||
bench.end(n);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
function main(conf) {
|
function main({ n, len, method }) {
|
||||||
const n = +conf.n;
|
|
||||||
const len = +conf.len;
|
|
||||||
|
|
||||||
const array = Array(len).fill(1);
|
const array = Array(len).fill(1);
|
||||||
var values, values2;
|
var values, values2;
|
||||||
|
|
||||||
switch (conf.method) {
|
switch (method) {
|
||||||
case '':
|
case '':
|
||||||
// Empty string falls through to next line as default, mostly for tests.
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'deepEqual_primitiveOnly':
|
case 'deepEqual_primitiveOnly':
|
||||||
|
@ -25,10 +25,9 @@ function createObj(source, add = '') {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function main(conf) {
|
function main({ size, n, method }) {
|
||||||
const size = conf.size;
|
// TODO: Fix this "hack". `n` should not be manipulated.
|
||||||
// TODO: Fix this "hack"
|
n = n / size;
|
||||||
const n = conf.n / size;
|
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
const source = Array.apply(null, Array(size));
|
const source = Array.apply(null, Array(size));
|
||||||
@ -36,7 +35,7 @@ function main(conf) {
|
|||||||
const expected = createObj(source);
|
const expected = createObj(source);
|
||||||
const expectedWrong = createObj(source, '4');
|
const expectedWrong = createObj(source, '4');
|
||||||
|
|
||||||
switch (conf.method) {
|
switch (method) {
|
||||||
case '':
|
case '':
|
||||||
// Empty string falls through to next line as default, mostly for tests.
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'deepEqual':
|
case 'deepEqual':
|
||||||
|
@ -15,7 +15,7 @@ const primValues = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const bench = common.createBenchmark(main, {
|
const bench = common.createBenchmark(main, {
|
||||||
prim: Object.keys(primValues),
|
primitive: Object.keys(primValues),
|
||||||
n: [25],
|
n: [25],
|
||||||
len: [1e5],
|
len: [1e5],
|
||||||
method: [
|
method: [
|
||||||
@ -30,10 +30,8 @@ const bench = common.createBenchmark(main, {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
function main(conf) {
|
function main({ n, len, primitive, method }) {
|
||||||
const prim = primValues[conf.prim];
|
const prim = primValues[primitive];
|
||||||
const n = +conf.n;
|
|
||||||
const len = +conf.len;
|
|
||||||
const actual = [];
|
const actual = [];
|
||||||
const expected = [];
|
const expected = [];
|
||||||
const expectedWrong = [];
|
const expectedWrong = [];
|
||||||
@ -52,7 +50,7 @@ function main(conf) {
|
|||||||
const expectedSet = new Set(expected);
|
const expectedSet = new Set(expected);
|
||||||
const expectedWrongSet = new Set(expectedWrong);
|
const expectedWrongSet = new Set(expectedWrong);
|
||||||
|
|
||||||
switch (conf.method) {
|
switch (method) {
|
||||||
case '':
|
case '':
|
||||||
// Empty string falls through to next line as default, mostly for tests.
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'deepEqual_Array':
|
case 'deepEqual_Array':
|
||||||
|
@ -14,7 +14,7 @@ const primValues = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const bench = common.createBenchmark(main, {
|
const bench = common.createBenchmark(main, {
|
||||||
prim: Object.keys(primValues),
|
primitive: Object.keys(primValues),
|
||||||
n: [1e6],
|
n: [1e6],
|
||||||
method: [
|
method: [
|
||||||
'deepEqual',
|
'deepEqual',
|
||||||
@ -24,16 +24,15 @@ const bench = common.createBenchmark(main, {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
function main(conf) {
|
function main({ n, primitive, method }) {
|
||||||
const prim = primValues[conf.prim];
|
const prim = primValues[primitive];
|
||||||
const n = +conf.n;
|
|
||||||
const actual = prim;
|
const actual = prim;
|
||||||
const expected = prim;
|
const expected = prim;
|
||||||
const expectedWrong = 'b';
|
const expectedWrong = 'b';
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
// Creates new array to avoid loop invariant code motion
|
// Creates new array to avoid loop invariant code motion
|
||||||
switch (conf.method) {
|
switch (method) {
|
||||||
case '':
|
case '':
|
||||||
// Empty string falls through to next line as default, mostly for tests.
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'deepEqual':
|
case 'deepEqual':
|
||||||
|
@ -38,15 +38,12 @@ function benchmark(method, n, values, values2) {
|
|||||||
bench.end(n);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
function main(conf) {
|
function main({ n, len, method }) {
|
||||||
const n = +conf.n;
|
|
||||||
const len = +conf.len;
|
|
||||||
|
|
||||||
const array = Array(len).fill(1);
|
const array = Array(len).fill(1);
|
||||||
|
|
||||||
var values, values2;
|
var values, values2;
|
||||||
|
|
||||||
switch (conf.method) {
|
switch (method) {
|
||||||
case '':
|
case '':
|
||||||
// Empty string falls through to next line as default, mostly for tests.
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'deepEqual_primitiveOnly':
|
case 'deepEqual_primitiveOnly':
|
||||||
|
@ -24,12 +24,8 @@ const bench = common.createBenchmark(main, {
|
|||||||
len: [1e6]
|
len: [1e6]
|
||||||
});
|
});
|
||||||
|
|
||||||
function main(conf) {
|
function main({ type, n, len, method }) {
|
||||||
const type = conf.type;
|
|
||||||
const clazz = global[type];
|
const clazz = global[type];
|
||||||
const n = +conf.n;
|
|
||||||
const len = +conf.len;
|
|
||||||
|
|
||||||
const actual = new clazz(len);
|
const actual = new clazz(len);
|
||||||
const expected = new clazz(len);
|
const expected = new clazz(len);
|
||||||
const expectedWrong = Buffer.alloc(len);
|
const expectedWrong = Buffer.alloc(len);
|
||||||
@ -37,7 +33,7 @@ function main(conf) {
|
|||||||
expectedWrong[wrongIndex] = 123;
|
expectedWrong[wrongIndex] = 123;
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
switch (conf.method) {
|
switch (method) {
|
||||||
case '':
|
case '':
|
||||||
// Empty string falls through to next line as default, mostly for tests.
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'deepEqual':
|
case 'deepEqual':
|
||||||
|
@ -13,15 +13,14 @@ const bench = common.createBenchmark(main, {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
function main(conf) {
|
function main({ n, method }) {
|
||||||
const n = +conf.n;
|
|
||||||
const throws = () => { throw new TypeError('foobar'); };
|
const throws = () => { throw new TypeError('foobar'); };
|
||||||
const doesNotThrow = () => { return 'foobar'; };
|
const doesNotThrow = () => { return 'foobar'; };
|
||||||
const regExp = /foobar/;
|
const regExp = /foobar/;
|
||||||
const message = 'failure';
|
const message = 'failure';
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
switch (conf.method) {
|
switch (method) {
|
||||||
case '':
|
case '':
|
||||||
// Empty string falls through to next line as default, mostly for tests.
|
// Empty string falls through to next line as default, mostly for tests.
|
||||||
case 'doesNotThrow':
|
case 'doesNotThrow':
|
||||||
@ -54,6 +53,6 @@ function main(conf) {
|
|||||||
bench.end(n);
|
bench.end(n);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unsupported method ${conf.method}`);
|
throw new Error(`Unsupported method ${method}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user