From c25d4d66dcfa9741eec9344c7e3f9595d20c9196 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 30 Dec 2017 03:59:27 +0100 Subject: [PATCH] benchmark: (es) use destructuring PR-URL: https://github.com/nodejs/node/pull/18250 Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- benchmark/es/defaultparams-bench.js | 6 +++--- benchmark/es/destructuring-bench.js | 6 +++--- benchmark/es/destructuring-object-bench.js | 6 +++--- benchmark/es/foreach-bench.js | 8 +++----- benchmark/es/map-bench.js | 6 +++--- benchmark/es/restparams-bench.js | 6 +++--- benchmark/es/spread-bench.js | 14 +++++++------- benchmark/es/string-concatenations.js | 6 ++---- benchmark/es/string-repeat.js | 8 +++----- 9 files changed, 30 insertions(+), 36 deletions(-) diff --git a/benchmark/es/defaultparams-bench.js b/benchmark/es/defaultparams-bench.js index 1393abbe54395c..ce2132718ca369 100644 --- a/benchmark/es/defaultparams-bench.js +++ b/benchmark/es/defaultparams-bench.js @@ -38,10 +38,10 @@ function runDefaultParams(n) { bench.end(n / 1e6); } -function main(conf) { - const n = +conf.millions * 1e6; +function main({ millions, method }) { + const n = millions * 1e6; - switch (conf.method) { + switch (method) { case '': // Empty string falls through to next line as default, mostly for tests. case 'withoutdefaults': diff --git a/benchmark/es/destructuring-bench.js b/benchmark/es/destructuring-bench.js index a6c9a81ae02895..f244506860d248 100644 --- a/benchmark/es/destructuring-bench.js +++ b/benchmark/es/destructuring-bench.js @@ -34,10 +34,10 @@ function runSwapDestructured(n) { bench.end(n / 1e6); } -function main(conf) { - const n = +conf.millions * 1e6; +function main({ millions, method }) { + const n = millions * 1e6; - switch (conf.method) { + switch (method) { case '': // Empty string falls through to next line as default, mostly for tests. case 'swap': diff --git a/benchmark/es/destructuring-object-bench.js b/benchmark/es/destructuring-object-bench.js index 63e085a2424430..73687f018de9dd 100644 --- a/benchmark/es/destructuring-object-bench.js +++ b/benchmark/es/destructuring-object-bench.js @@ -33,10 +33,10 @@ function runDestructured(n) { bench.end(n / 1e6); } -function main(conf) { - const n = +conf.millions * 1e6; +function main({ millions, method }) { + const n = millions * 1e6; - switch (conf.method) { + switch (method) { case '': // Empty string falls through to next line as default, mostly for tests. case 'normal': diff --git a/benchmark/es/foreach-bench.js b/benchmark/es/foreach-bench.js index 62aa02236fc7ae..c7caa7cee6f461 100644 --- a/benchmark/es/foreach-bench.js +++ b/benchmark/es/foreach-bench.js @@ -52,17 +52,15 @@ function useForEach(n, items) { bench.end(n / 1e6); } -function main(conf) { - const n = +conf.millions * 1e6; - const count = +conf.count; - +function main({ millions, count, method }) { + const n = millions * 1e6; const items = new Array(count); var i; var fn; for (i = 0; i < count; i++) items[i] = i; - switch (conf.method) { + switch (method) { case '': // Empty string falls through to next line as default, mostly for tests. case 'for': diff --git a/benchmark/es/map-bench.js b/benchmark/es/map-bench.js index 035ed1a22aaf91..ba8e35c2eb934f 100644 --- a/benchmark/es/map-bench.js +++ b/benchmark/es/map-bench.js @@ -108,10 +108,10 @@ function runMap(n) { bench.end(n / 1e6); } -function main(conf) { - const n = +conf.millions * 1e6; +function main({ millions, method }) { + const n = millions * 1e6; - switch (conf.method) { + switch (method) { case '': // Empty string falls through to next line as default, mostly for tests. case 'object': diff --git a/benchmark/es/restparams-bench.js b/benchmark/es/restparams-bench.js index 32fa985dedb806..78299d292ce6f6 100644 --- a/benchmark/es/restparams-bench.js +++ b/benchmark/es/restparams-bench.js @@ -60,10 +60,10 @@ function runUseArguments(n) { bench.end(n / 1e6); } -function main(conf) { - const n = +conf.millions * 1e6; +function main({ millions, method }) { + const n = millions * 1e6; - switch (conf.method) { + switch (method) { case '': // Empty string falls through to next line as default, mostly for tests. case 'copy': diff --git a/benchmark/es/spread-bench.js b/benchmark/es/spread-bench.js index b6dfb5963e7acc..3c6cc93ea4f817 100644 --- a/benchmark/es/spread-bench.js +++ b/benchmark/es/spread-bench.js @@ -23,16 +23,16 @@ function makeTest(count, rest) { } } -function main(conf) { - const n = +conf.millions * 1e6; - const ctx = conf.context === 'context' ? {} : null; - var fn = makeTest(conf.count, conf.rest); - const args = new Array(conf.count); +function main({ millions, context, count, rest, method }) { + const n = millions * 1e6; + const ctx = context === 'context' ? {} : null; + var fn = makeTest(count, rest); + const args = new Array(count); var i; - for (i = 0; i < conf.count; i++) + for (i = 0; i < count; i++) args[i] = i; - switch (conf.method) { + switch (method) { case '': // Empty string falls through to next line as default, mostly for tests. case 'apply': diff --git a/benchmark/es/string-concatenations.js b/benchmark/es/string-concatenations.js index b7f5c319361c6c..a40b7fa8c3b9f9 100644 --- a/benchmark/es/string-concatenations.js +++ b/benchmark/es/string-concatenations.js @@ -17,15 +17,13 @@ const configs = { const bench = common.createBenchmark(main, configs); -function main(conf) { - const n = +conf.n; - +function main({ n, mode }) { const str = 'abc'; const num = 123; let string; - switch (conf.mode) { + switch (mode) { case '': // Empty string falls through to next line as default, mostly for tests. case 'multi-concat': diff --git a/benchmark/es/string-repeat.js b/benchmark/es/string-repeat.js index 1ddc7db78c7f86..e5bdbb5cc193c1 100644 --- a/benchmark/es/string-repeat.js +++ b/benchmark/es/string-repeat.js @@ -12,14 +12,12 @@ const configs = { const bench = common.createBenchmark(main, configs); -function main(conf) { - const n = +conf.n; - const size = +conf.size; - const character = conf.encoding === 'ascii' ? 'a' : '\ud83d\udc0e'; // '🐎' +function main({ n, size, encoding, mode }) { + const character = encoding === 'ascii' ? 'a' : '\ud83d\udc0e'; // '🐎' let str; - switch (conf.mode) { + switch (mode) { case '': // Empty string falls through to next line as default, mostly for tests. case 'Array':