Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: use destructuring and more #18250

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8d5f560
benchmark: (arrays) use destructuring
BridgeAR Dec 30, 2017
eb5a92d
benchmark: (assert) use destructuring
BridgeAR Dec 30, 2017
a48a321
benchmark: (url) use destructuring
BridgeAR Dec 30, 2017
52fc567
benchmark: (zlib) use destructuring
BridgeAR Dec 30, 2017
e6eb394
benchmark: (util/v8/vm) use destructuring
BridgeAR Dec 30, 2017
8e977c3
benchmark: (tls) use destructuring
BridgeAR Dec 30, 2017
0d05d11
benchmark: (timers) use destructuring
BridgeAR Dec 30, 2017
912458b
benchmark: (streams) use destructuring
BridgeAR Dec 30, 2017
1cc8db1
benchmark: (querystring) use destructuring
BridgeAR Dec 30, 2017
f30a2bd
benchmark: (process) use destructuring
BridgeAR Dec 30, 2017
b2e8cca
benchmark: (net) use destructuring
BridgeAR Dec 30, 2017
c5879c3
benchmark: (os) use destructuring
BridgeAR Dec 30, 2017
c5a1819
benchmark: (path) use destructuring
BridgeAR Dec 30, 2017
ed55a5e
benchmark: (string_decoder) use destructuring
BridgeAR Dec 30, 2017
430bb2c
benchmark: (http2) use destructuring
BridgeAR Dec 30, 2017
2f49067
benchmark: (misc) use destructuring
BridgeAR Dec 30, 2017
69bfcbc
benchmark: (http) use destructuring
BridgeAR Dec 30, 2017
cdfb609
benchmark: (fs) use destructuring
BridgeAR Dec 30, 2017
abc7eec
benchmark: (es) use destructuring
BridgeAR Dec 30, 2017
3011f0a
benchmark: (events) use destructuring
BridgeAR Dec 30, 2017
f2d920b
benchmark: (buffers) use destructuring
BridgeAR Dec 30, 2017
d766d57
benchmark: (child_process) use destructuring
BridgeAR Dec 30, 2017
59b5962
benchmark: (dgram) use destructuring
BridgeAR Dec 30, 2017
bf6ea9e
benchmark: (async_hooks/dns/cluster/domain/module) use destructuring
BridgeAR Dec 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions benchmark/arrays/var-int.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ const bench = common.createBenchmark(main, {
n: [25]
});

function main(conf) {
const type = conf.type;
function main({ type, n }) {
const clazz = global[type];
const n = +conf.n;

bench.start();
const arr = new clazz(n * 1e6);
Expand Down
4 changes: 1 addition & 3 deletions benchmark/arrays/zero-float.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ const bench = common.createBenchmark(main, {
n: [25]
});

function main(conf) {
const type = conf.type;
function main({ type, n }) {
const clazz = global[type];
const n = +conf.n;

bench.start();
const arr = new clazz(n * 1e6);
Expand Down
4 changes: 1 addition & 3 deletions benchmark/arrays/zero-int.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ const bench = common.createBenchmark(main, {
n: [25]
});

function main(conf) {
const type = conf.type;
function main({ type, n }) {
const clazz = global[type];
const n = +conf.n;

bench.start();
const arr = new clazz(n * 1e6);
Expand Down
6 changes: 2 additions & 4 deletions benchmark/assert/deepequal-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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':
Expand Down
7 changes: 2 additions & 5 deletions benchmark/assert/deepequal-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
9 changes: 4 additions & 5 deletions benchmark/assert/deepequal-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@ 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));
const actual = createObj(source);
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':
Expand Down
10 changes: 4 additions & 6 deletions benchmark/assert/deepequal-prims-and-objs-big-array-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const primValues = {
};

const bench = common.createBenchmark(main, {
prim: Object.keys(primValues),
primitive: Object.keys(primValues),
n: [25],
len: [1e5],
method: [
Expand All @@ -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 = [];
Expand All @@ -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':
Expand Down
9 changes: 4 additions & 5 deletions benchmark/assert/deepequal-prims-and-objs-big-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const primValues = {
};

const bench = common.createBenchmark(main, {
prim: Object.keys(primValues),
primitive: Object.keys(primValues),
n: [1e6],
method: [
'deepEqual',
Expand All @@ -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':
Expand Down
7 changes: 2 additions & 5 deletions benchmark/assert/deepequal-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
8 changes: 2 additions & 6 deletions benchmark/assert/deepequal-typedarrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,16 @@ 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);
const wrongIndex = Math.floor(len / 2);
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':
Expand Down
7 changes: 3 additions & 4 deletions benchmark/assert/throws.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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}`);
}
}
6 changes: 2 additions & 4 deletions benchmark/async_hooks/gc-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ function endAfterGC(n) {
});
}

function main(conf) {
const n = +conf.n;

switch (conf.method) {
function main({ n, method }) {
switch (method) {
case 'trackingEnabled':
bench.start();
for (let i = 0; i < n; i++) {
Expand Down
3 changes: 1 addition & 2 deletions benchmark/buffers/buffer-base64-decode-wrapped.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const bench = common.createBenchmark(main, {
n: [32],
});

function main(conf) {
const n = +conf.n;
function main({ n }) {
const charsPerLine = 76;
const linesCount = 8 << 16;
const bytesCount = charsPerLine * linesCount / 4 * 3;
Expand Down
3 changes: 1 addition & 2 deletions benchmark/buffers/buffer-base64-decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const bench = common.createBenchmark(main, {
n: [32],
});

function main(conf) {
const n = +conf.n;
function main({ n }) {
const s = 'abcd'.repeat(8 << 20);
// eslint-disable-next-line no-unescaped-regexp-dot
s.match(/./); // Flatten string.
Expand Down
4 changes: 1 addition & 3 deletions benchmark/buffers/buffer-base64-encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ const bench = common.createBenchmark(main, {
n: [32]
});

function main(conf) {
const n = +conf.n;
const len = +conf.len;
function main({ n, len }) {
const b = Buffer.allocUnsafe(len);
let s = '';
let i;
Expand Down
6 changes: 1 addition & 5 deletions benchmark/buffers/buffer-bytelength.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ const chars = [
'𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢' // 4 bytes
];

function main(conf) {
const n = conf.n | 0;
const len = conf.len | 0;
const encoding = conf.encoding;

function main({ n, len, encoding }) {
var strings = [];
var results;
if (encoding === 'buffer') {
Expand Down
6 changes: 2 additions & 4 deletions benchmark/buffers/buffer-compare-instance-method.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ const bench = common.createBenchmark(main, {
millions: [1]
});

function main(conf) {
const iter = (conf.millions >>> 0) * 1e6;
const size = (conf.size >>> 0);
const args = (conf.args >>> 0);
function main({ millions, size, args }) {
const iter = millions * 1e6;
const b0 = Buffer.alloc(size, 'a');
const b1 = Buffer.alloc(size, 'a');
const b0Len = b0.length;
Expand Down
16 changes: 7 additions & 9 deletions benchmark/buffers/buffer-compare-offset.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ function compareUsingOffset(b0, b1, len, iter) {
bench.end(iter / 1e6);
}

function main(conf) {
const iter = (conf.millions >>> 0) * 1e6;
const size = (conf.size >>> 0);
const method =
conf.method === 'slice' ? compareUsingSlice : compareUsingOffset;
method(Buffer.alloc(size, 'a'),
Buffer.alloc(size, 'b'),
size >> 1,
iter);
function main({ millions, size, method }) {
const iter = millions * 1e6;
const fn = method === 'slice' ? compareUsingSlice : compareUsingOffset;
fn(Buffer.alloc(size, 'a'),
Buffer.alloc(size, 'b'),
size >> 1,
iter);
}
5 changes: 2 additions & 3 deletions benchmark/buffers/buffer-compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ const bench = common.createBenchmark(main, {
millions: [1]
});

function main(conf) {
const iter = (conf.millions >>> 0) * 1e6;
const size = (conf.size >>> 0);
function main({ millions, size }) {
const iter = millions * 1e6;
const b0 = Buffer.alloc(size, 'a');
const b1 = Buffer.alloc(size, 'a');

Expand Down
10 changes: 3 additions & 7 deletions benchmark/buffers/buffer-concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ const bench = common.createBenchmark(main, {
n: [1024]
});

function main(conf) {
const n = +conf.n;
const size = +conf.pieceSize;
const pieces = +conf.pieces;

function main({ n, pieces, pieceSize, withTotalLength }) {
const list = new Array(pieces);
list.fill(Buffer.allocUnsafe(size));
list.fill(Buffer.allocUnsafe(pieceSize));

const totalLength = conf.withTotalLength ? pieces * size : undefined;
const totalLength = withTotalLength ? pieces * pieceSize : undefined;

bench.start();
for (var i = 0; i < n * 1024; i++) {
Expand Down
6 changes: 2 additions & 4 deletions benchmark/buffers/buffer-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ const bench = common.createBenchmark(main, {
n: [1024]
});

function main(conf) {
const len = +conf.len;
const n = +conf.n;
switch (conf.type) {
function main({ len, n, type }) {
switch (type) {
case '':
case 'fast-alloc':
bench.start();
Expand Down
7 changes: 2 additions & 5 deletions benchmark/buffers/buffer-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ const bench = common.createBenchmark(main, {
n: [2048]
});

function main(conf) {
const len = +conf.len;
const n = +conf.n;

function main({ len, n, source }) {
const array = new Array(len).fill(42);
const arrayBuf = new ArrayBuffer(len);
const str = 'a'.repeat(len);
Expand All @@ -31,7 +28,7 @@ function main(conf) {

var i;

switch (conf.source) {
switch (source) {
case 'array':
bench.start();
for (i = 0; i < n * 1024; i++) {
Expand Down
4 changes: 1 addition & 3 deletions benchmark/buffers/buffer-hex.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ const bench = common.createBenchmark(main, {
n: [1e7]
});

function main(conf) {
const len = conf.len | 0;
const n = conf.n | 0;
function main({ len, n }) {
const buf = Buffer.alloc(len);

for (let i = 0; i < buf.length; i++)
Expand Down
Loading