summaryrefslogtreecommitdiff
path: root/benchmark/assert
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2017-12-30 03:54:30 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-01-23 01:29:15 +0100
commit366fd03af00407e9b45d91d9df66b3ab34b10f35 (patch)
treecde109f3a384d1055bc71322d6fc2f1347d759f5 /benchmark/assert
parent0beef3f03032a97bb0bda1539add7506a11cf2a8 (diff)
downloadandroid-node-v8-366fd03af00407e9b45d91d9df66b3ab34b10f35.tar.gz
android-node-v8-366fd03af00407e9b45d91d9df66b3ab34b10f35.tar.bz2
android-node-v8-366fd03af00407e9b45d91d9df66b3ab34b10f35.zip
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>
Diffstat (limited to 'benchmark/assert')
-rw-r--r--benchmark/assert/deepequal-buffer.js6
-rw-r--r--benchmark/assert/deepequal-map.js7
-rw-r--r--benchmark/assert/deepequal-object.js9
-rw-r--r--benchmark/assert/deepequal-prims-and-objs-big-array-set.js10
-rw-r--r--benchmark/assert/deepequal-prims-and-objs-big-loop.js9
-rw-r--r--benchmark/assert/deepequal-set.js7
-rw-r--r--benchmark/assert/deepequal-typedarrays.js8
-rw-r--r--benchmark/assert/throws.js7
8 files changed, 23 insertions, 40 deletions
diff --git a/benchmark/assert/deepequal-buffer.js b/benchmark/assert/deepequal-buffer.js
index d4495af69b..0e7494544d 100644
--- a/benchmark/assert/deepequal-buffer.js
+++ b/benchmark/assert/deepequal-buffer.js
@@ -13,9 +13,7 @@ const bench = common.createBenchmark(main, {
]
});
-function main(conf) {
- const n = +conf.n;
- const len = +conf.len;
+function main({ len, n, method }) {
var i;
const data = Buffer.allocUnsafe(len + 1);
@@ -26,7 +24,7 @@ function main(conf) {
data.copy(expected);
data.copy(expectedWrong);
- switch (conf.method) {
+ switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'deepEqual':
diff --git a/benchmark/assert/deepequal-map.js b/benchmark/assert/deepequal-map.js
index 4976f26198..085274e8bf 100644
--- a/benchmark/assert/deepequal-map.js
+++ b/benchmark/assert/deepequal-map.js
@@ -38,14 +38,11 @@ function benchmark(method, n, values, values2) {
bench.end(n);
}
-function main(conf) {
- const n = +conf.n;
- const len = +conf.len;
-
+function main({ n, len, method }) {
const array = Array(len).fill(1);
var values, values2;
- switch (conf.method) {
+ switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'deepEqual_primitiveOnly':
diff --git a/benchmark/assert/deepequal-object.js b/benchmark/assert/deepequal-object.js
index 4ad3704408..2c2549d584 100644
--- a/benchmark/assert/deepequal-object.js
+++ b/benchmark/assert/deepequal-object.js
@@ -25,10 +25,9 @@ function createObj(source, add = '') {
}));
}
-function main(conf) {
- const size = conf.size;
- // TODO: Fix this "hack"
- const n = conf.n / size;
+function main({ size, n, method }) {
+ // TODO: Fix this "hack". `n` should not be manipulated.
+ n = n / size;
var i;
const source = Array.apply(null, Array(size));
@@ -36,7 +35,7 @@ function main(conf) {
const expected = createObj(source);
const expectedWrong = createObj(source, '4');
- switch (conf.method) {
+ switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'deepEqual':
diff --git a/benchmark/assert/deepequal-prims-and-objs-big-array-set.js b/benchmark/assert/deepequal-prims-and-objs-big-array-set.js
index 19337d7828..04802a7692 100644
--- a/benchmark/assert/deepequal-prims-and-objs-big-array-set.js
+++ b/benchmark/assert/deepequal-prims-and-objs-big-array-set.js
@@ -15,7 +15,7 @@ const primValues = {
};
const bench = common.createBenchmark(main, {
- prim: Object.keys(primValues),
+ primitive: Object.keys(primValues),
n: [25],
len: [1e5],
method: [
@@ -30,10 +30,8 @@ const bench = common.createBenchmark(main, {
]
});
-function main(conf) {
- const prim = primValues[conf.prim];
- const n = +conf.n;
- const len = +conf.len;
+function main({ n, len, primitive, method }) {
+ const prim = primValues[primitive];
const actual = [];
const expected = [];
const expectedWrong = [];
@@ -52,7 +50,7 @@ function main(conf) {
const expectedSet = new Set(expected);
const expectedWrongSet = new Set(expectedWrong);
- switch (conf.method) {
+ switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'deepEqual_Array':
diff --git a/benchmark/assert/deepequal-prims-and-objs-big-loop.js b/benchmark/assert/deepequal-prims-and-objs-big-loop.js
index 4a345f27c2..09797dfaf2 100644
--- a/benchmark/assert/deepequal-prims-and-objs-big-loop.js
+++ b/benchmark/assert/deepequal-prims-and-objs-big-loop.js
@@ -14,7 +14,7 @@ const primValues = {
};
const bench = common.createBenchmark(main, {
- prim: Object.keys(primValues),
+ primitive: Object.keys(primValues),
n: [1e6],
method: [
'deepEqual',
@@ -24,16 +24,15 @@ const bench = common.createBenchmark(main, {
]
});
-function main(conf) {
- const prim = primValues[conf.prim];
- const n = +conf.n;
+function main({ n, primitive, method }) {
+ const prim = primValues[primitive];
const actual = prim;
const expected = prim;
const expectedWrong = 'b';
var i;
// Creates new array to avoid loop invariant code motion
- switch (conf.method) {
+ switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'deepEqual':
diff --git a/benchmark/assert/deepequal-set.js b/benchmark/assert/deepequal-set.js
index aa0ebc0648..ebcf33cc6d 100644
--- a/benchmark/assert/deepequal-set.js
+++ b/benchmark/assert/deepequal-set.js
@@ -38,15 +38,12 @@ function benchmark(method, n, values, values2) {
bench.end(n);
}
-function main(conf) {
- const n = +conf.n;
- const len = +conf.len;
-
+function main({ n, len, method }) {
const array = Array(len).fill(1);
var values, values2;
- switch (conf.method) {
+ switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'deepEqual_primitiveOnly':
diff --git a/benchmark/assert/deepequal-typedarrays.js b/benchmark/assert/deepequal-typedarrays.js
index 8e8cc4b083..01546801ff 100644
--- a/benchmark/assert/deepequal-typedarrays.js
+++ b/benchmark/assert/deepequal-typedarrays.js
@@ -24,12 +24,8 @@ const bench = common.createBenchmark(main, {
len: [1e6]
});
-function main(conf) {
- const type = conf.type;
+function main({ type, n, len, method }) {
const clazz = global[type];
- const n = +conf.n;
- const len = +conf.len;
-
const actual = new clazz(len);
const expected = new clazz(len);
const expectedWrong = Buffer.alloc(len);
@@ -37,7 +33,7 @@ function main(conf) {
expectedWrong[wrongIndex] = 123;
var i;
- switch (conf.method) {
+ switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'deepEqual':
diff --git a/benchmark/assert/throws.js b/benchmark/assert/throws.js
index 075e227f88..bffde7cbc1 100644
--- a/benchmark/assert/throws.js
+++ b/benchmark/assert/throws.js
@@ -13,15 +13,14 @@ const bench = common.createBenchmark(main, {
]
});
-function main(conf) {
- const n = +conf.n;
+function main({ n, method }) {
const throws = () => { throw new TypeError('foobar'); };
const doesNotThrow = () => { return 'foobar'; };
const regExp = /foobar/;
const message = 'failure';
var i;
- switch (conf.method) {
+ switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'doesNotThrow':
@@ -54,6 +53,6 @@ function main(conf) {
bench.end(n);
break;
default:
- throw new Error(`Unsupported method ${conf.method}`);
+ throw new Error(`Unsupported method ${method}`);
}
}