diff --git a/benchmark/buffers/buffer-base64-decode-wrapped.js b/benchmark/buffers/buffer-base64-decode-wrapped.js index 3140cd5525ad07..61e3bb654ee7c0 100644 --- a/benchmark/buffers/buffer-base64-decode-wrapped.js +++ b/benchmark/buffers/buffer-base64-decode-wrapped.js @@ -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; diff --git a/benchmark/buffers/buffer-base64-decode.js b/benchmark/buffers/buffer-base64-decode.js index 6a9002df383a8f..492922fb2b6eac 100644 --- a/benchmark/buffers/buffer-base64-decode.js +++ b/benchmark/buffers/buffer-base64-decode.js @@ -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. diff --git a/benchmark/buffers/buffer-base64-encode.js b/benchmark/buffers/buffer-base64-encode.js index 509fcd9a33c9d4..d8b601bbd181f4 100644 --- a/benchmark/buffers/buffer-base64-encode.js +++ b/benchmark/buffers/buffer-base64-encode.js @@ -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; diff --git a/benchmark/buffers/buffer-bytelength.js b/benchmark/buffers/buffer-bytelength.js index fc6dfcf2301eaf..0617b4feb3f140 100644 --- a/benchmark/buffers/buffer-bytelength.js +++ b/benchmark/buffers/buffer-bytelength.js @@ -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') { diff --git a/benchmark/buffers/buffer-compare-instance-method.js b/benchmark/buffers/buffer-compare-instance-method.js index ff3bc4c1abda98..a3433803b79537 100644 --- a/benchmark/buffers/buffer-compare-instance-method.js +++ b/benchmark/buffers/buffer-compare-instance-method.js @@ -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; diff --git a/benchmark/buffers/buffer-compare-offset.js b/benchmark/buffers/buffer-compare-offset.js index 96719abfbe5618..850fe11d3f429e 100644 --- a/benchmark/buffers/buffer-compare-offset.js +++ b/benchmark/buffers/buffer-compare-offset.js @@ -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); } diff --git a/benchmark/buffers/buffer-compare.js b/benchmark/buffers/buffer-compare.js index ad6519cd102340..f7abb4b3d94ffa 100644 --- a/benchmark/buffers/buffer-compare.js +++ b/benchmark/buffers/buffer-compare.js @@ -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'); diff --git a/benchmark/buffers/buffer-concat.js b/benchmark/buffers/buffer-concat.js index a27e132193ef41..3f9cffc06a6a7e 100644 --- a/benchmark/buffers/buffer-concat.js +++ b/benchmark/buffers/buffer-concat.js @@ -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++) { diff --git a/benchmark/buffers/buffer-creation.js b/benchmark/buffers/buffer-creation.js index 4ca0a049228f6c..73e620955e91db 100644 --- a/benchmark/buffers/buffer-creation.js +++ b/benchmark/buffers/buffer-creation.js @@ -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(); diff --git a/benchmark/buffers/buffer-from.js b/benchmark/buffers/buffer-from.js index 50cfbc887aa0b9..6f2358bcf296ab 100644 --- a/benchmark/buffers/buffer-from.js +++ b/benchmark/buffers/buffer-from.js @@ -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); @@ -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++) { diff --git a/benchmark/buffers/buffer-hex.js b/benchmark/buffers/buffer-hex.js index d05bb832b3068c..1bdef81139ffe7 100644 --- a/benchmark/buffers/buffer-hex.js +++ b/benchmark/buffers/buffer-hex.js @@ -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++) diff --git a/benchmark/buffers/buffer-indexof-number.js b/benchmark/buffers/buffer-indexof-number.js index 2e6e10b9f33d40..91bff0d54bb7eb 100644 --- a/benchmark/buffers/buffer-indexof-number.js +++ b/benchmark/buffers/buffer-indexof-number.js @@ -8,16 +8,14 @@ const bench = common.createBenchmark(main, { n: [1e7] }); -function main(conf) { - const n = +conf.n; - const search = +conf.value; +function main({ n, value }) { const aliceBuffer = fs.readFileSync( path.resolve(__dirname, '../fixtures/alice.html') ); bench.start(); for (var i = 0; i < n; i++) { - aliceBuffer.indexOf(search, 0, undefined); + aliceBuffer.indexOf(value, 0, undefined); } bench.end(n); } diff --git a/benchmark/buffers/buffer-indexof.js b/benchmark/buffers/buffer-indexof.js index 1545475269a025..c98d15320aaaae 100644 --- a/benchmark/buffers/buffer-indexof.js +++ b/benchmark/buffers/buffer-indexof.js @@ -25,16 +25,13 @@ const bench = common.createBenchmark(main, { search: searchStrings, encoding: ['undefined', 'utf8', 'ucs2', 'binary'], type: ['buffer', 'string'], - iter: [1] + iter: [100000] }); -function main(conf) { - const iter = (conf.iter) * 100000; +function main({ iter, search, encoding, type }) { var aliceBuffer = fs.readFileSync( path.resolve(__dirname, '../fixtures/alice.html') ); - var search = conf.search; - var encoding = conf.encoding; if (encoding === 'undefined') { encoding = undefined; @@ -44,7 +41,7 @@ function main(conf) { aliceBuffer = Buffer.from(aliceBuffer.toString(), encoding); } - if (conf.type === 'buffer') { + if (type === 'buffer') { search = Buffer.from(Buffer.from(search).toString(), encoding); } diff --git a/benchmark/buffers/buffer-iterate.js b/benchmark/buffers/buffer-iterate.js index 4e911caa72ce14..8531e1cae82115 100644 --- a/benchmark/buffers/buffer-iterate.js +++ b/benchmark/buffers/buffer-iterate.js @@ -16,14 +16,11 @@ const methods = { 'iterator': benchIterator }; -function main(conf) { - const len = +conf.size; - const clazz = conf.type === 'fast' ? Buffer : SlowBuffer; - const buffer = new clazz(len); +function main({ size, type, method, n }) { + const clazz = type === 'fast' ? Buffer : SlowBuffer; + const buffer = new clazz(size); buffer.fill(0); - - const method = conf.method || 'for'; - methods[method](buffer, conf.n); + methods[method || 'for'](buffer, n); } diff --git a/benchmark/buffers/buffer-read.js b/benchmark/buffers/buffer-read.js index 339da75befce4d..41e842f3123623 100644 --- a/benchmark/buffers/buffer-read.js +++ b/benchmark/buffers/buffer-read.js @@ -25,13 +25,12 @@ const bench = common.createBenchmark(main, { millions: [1] }); -function main(conf) { - const noAssert = conf.noAssert === 'true'; - const len = +conf.millions * 1e6; - const clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer; +function main({ noAssert, millions, buf, type }) { + noAssert = noAssert === 'true'; + const len = millions * 1e6; + const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer; const buff = new clazz(8); - const type = conf.type || 'UInt8'; - const fn = `read${type}`; + const fn = `read${type || 'UInt8'}`; buff.writeDoubleLE(0, 0, noAssert); const testFunction = new Function('buff', ` diff --git a/benchmark/buffers/buffer-slice.js b/benchmark/buffers/buffer-slice.js index 0067d02d8c7931..2e52475da91866 100644 --- a/benchmark/buffers/buffer-slice.js +++ b/benchmark/buffers/buffer-slice.js @@ -10,9 +10,8 @@ const bench = common.createBenchmark(main, { const buf = Buffer.allocUnsafe(1024); const slowBuf = new SlowBuffer(1024); -function main(conf) { - const n = +conf.n; - const b = conf.type === 'fast' ? buf : slowBuf; +function main({ n, type }) { + const b = type === 'fast' ? buf : slowBuf; bench.start(); for (var i = 0; i < n * 1024; i++) { b.slice(10, 256); diff --git a/benchmark/buffers/buffer-swap.js b/benchmark/buffers/buffer-swap.js index 05cde002943f4a..8f6e1f51d3a0f2 100644 --- a/benchmark/buffers/buffer-swap.js +++ b/benchmark/buffers/buffer-swap.js @@ -72,13 +72,9 @@ function genMethod(method) { return (new Function(fnString))(); } -function main(conf) { - const method = conf.method || 'swap16'; - const len = conf.len | 0; - const n = conf.n | 0; - const aligned = conf.aligned || 'true'; +function main({ method, len, n, aligned = 'true' }) { const buf = createBuffer(len, aligned === 'true'); - const bufferSwap = genMethod(method); + const bufferSwap = genMethod(method || 'swap16'); bufferSwap(n, buf); bench.start(); diff --git a/benchmark/buffers/buffer-tojson.js b/benchmark/buffers/buffer-tojson.js index 19a6fe89474838..71936fb622eae6 100644 --- a/benchmark/buffers/buffer-tojson.js +++ b/benchmark/buffers/buffer-tojson.js @@ -7,9 +7,8 @@ const bench = common.createBenchmark(main, { len: [0, 10, 256, 4 * 1024] }); -function main(conf) { - const n = +conf.n; - const buf = Buffer.allocUnsafe(+conf.len); +function main({ n, len }) { + const buf = Buffer.allocUnsafe(len); bench.start(); for (var i = 0; i < n; ++i) diff --git a/benchmark/buffers/buffer-tostring.js b/benchmark/buffers/buffer-tostring.js index 49916fca4023ca..b2a14d8aec55ce 100644 --- a/benchmark/buffers/buffer-tostring.js +++ b/benchmark/buffers/buffer-tostring.js @@ -9,11 +9,7 @@ const bench = common.createBenchmark(main, { n: [1e7] }); -function main(conf) { - var encoding = conf.encoding; - const args = conf.args | 0; - const len = conf.len | 0; - const n = conf.n | 0; +function main({ encoding, args, len, n }) { const buf = Buffer.alloc(len, 42); if (encoding.length === 0) diff --git a/benchmark/buffers/buffer-write-string.js b/benchmark/buffers/buffer-write-string.js index 927aa0b68466ef..37d4fda52c04e3 100644 --- a/benchmark/buffers/buffer-write-string.js +++ b/benchmark/buffers/buffer-write-string.js @@ -10,12 +10,7 @@ const bench = common.createBenchmark(main, { n: [1e7] }); -function main(conf) { - const len = +conf.len; - const n = +conf.n; - const encoding = conf.encoding; - const args = conf.args; - +function main({ len, n, encoding, args }) { const string = 'a'.repeat(len); const buf = Buffer.allocUnsafe(len); diff --git a/benchmark/buffers/buffer-write.js b/benchmark/buffers/buffer-write.js index b500a13dedcccd..ce2fbe3103cb83 100644 --- a/benchmark/buffers/buffer-write.js +++ b/benchmark/buffers/buffer-write.js @@ -45,13 +45,11 @@ const mod = { writeUInt32LE: UINT32 }; -function main(conf) { - const noAssert = conf.noAssert === 'true'; - const len = +conf.millions * 1e6; - const clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer; +function main({ noAssert, millions, buf, type }) { + const len = millions * 1e6; + const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer; const buff = new clazz(8); - const type = conf.type || 'UInt8'; - const fn = `write${type}`; + const fn = `write${type || 'UInt8'}`; if (/Int/.test(fn)) benchInt(buff, fn, len, noAssert); @@ -63,7 +61,7 @@ function benchInt(buff, fn, len, noAssert) { const m = mod[fn]; const testFunction = new Function('buff', ` for (var i = 0; i !== ${len}; i++) { - buff.${fn}(i & ${m}, 0, ${JSON.stringify(noAssert)}); + buff.${fn}(i & ${m}, 0, ${noAssert}); } `); bench.start(); @@ -74,7 +72,7 @@ function benchInt(buff, fn, len, noAssert) { function benchFloat(buff, fn, len, noAssert) { const testFunction = new Function('buff', ` for (var i = 0; i !== ${len}; i++) { - buff.${fn}(i, 0, ${JSON.stringify(noAssert)}); + buff.${fn}(i, 0, ${noAssert}); } `); bench.start(); diff --git a/benchmark/buffers/buffer_zero.js b/benchmark/buffers/buffer_zero.js index 06ca50bbb99ee7..06b68c313f1241 100644 --- a/benchmark/buffers/buffer_zero.js +++ b/benchmark/buffers/buffer_zero.js @@ -10,13 +10,12 @@ const bench = common.createBenchmark(main, { const zeroBuffer = Buffer.alloc(0); const zeroString = ''; -function main(conf) { - const n = +conf.n; +function main({ n, type }) { bench.start(); - if (conf.type === 'buffer') + if (type === 'buffer') for (let i = 0; i < n * 1024; i++) Buffer.from(zeroBuffer); - else if (conf.type === 'string') + else if (type === 'string') for (let i = 0; i < n * 1024; i++) Buffer.from(zeroString); bench.end(n); diff --git a/benchmark/buffers/dataview-set.js b/benchmark/buffers/dataview-set.js index 0dd4598ab7f1c5..ee5acfb1c1f72c 100644 --- a/benchmark/buffers/dataview-set.js +++ b/benchmark/buffers/dataview-set.js @@ -39,11 +39,11 @@ const mod = { setUint32: UINT32 }; -function main(conf) { - const len = +conf.millions * 1e6; +function main({ millions, type }) { + type = type || 'Uint8'; + const len = millions * 1e6; const ab = new ArrayBuffer(8); const dv = new DataView(ab, 0, 8); - const type = conf.type || 'Uint8'; const le = /LE$/.test(type); const fn = `set${type.replace(/[LB]E$/, '')}`;