From e9c426b35bf18c2aebce17beffe27a84e9af6848 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 30 Dec 2017 03:57:38 +0100 Subject: [PATCH] benchmark: (misc) use destructuring PR-URL: https://github.com/nodejs/node/pull/18250 Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- benchmark/misc/freelist.js | 3 +-- benchmark/misc/function_call/index.js | 8 ++++---- benchmark/misc/object-property-bench.js | 6 +++--- benchmark/misc/punycode.js | 6 ++---- benchmark/misc/startup.js | 3 +-- benchmark/misc/util-extend-vs-object-assign.js | 10 ++++------ 6 files changed, 15 insertions(+), 21 deletions(-) diff --git a/benchmark/misc/freelist.js b/benchmark/misc/freelist.js index 461f4b3e4c8960..0530255728ffeb 100644 --- a/benchmark/misc/freelist.js +++ b/benchmark/misc/freelist.js @@ -8,9 +8,8 @@ const bench = common.createBenchmark(main, { flags: ['--expose-internals'] }); -function main(conf) { +function main({ n }) { const FreeList = require('internal/freelist'); - const n = conf.n; const poolSize = 1000; const list = new FreeList('test', poolSize, Object); var i; diff --git a/benchmark/misc/function_call/index.js b/benchmark/misc/function_call/index.js index 6a2595d2ae188d..91efa573597cc7 100644 --- a/benchmark/misc/function_call/index.js +++ b/benchmark/misc/function_call/index.js @@ -31,13 +31,13 @@ const bench = common.createBenchmark(main, { millions: [1, 10, 50] }); -function main(conf) { - const n = +conf.millions * 1e6; +function main({ millions, type }) { + const n = millions * 1e6; - const fn = conf.type === 'cxx' ? cxx : js; + const fn = type === 'cxx' ? cxx : js; bench.start(); for (var i = 0; i < n; i++) { fn(); } - bench.end(+conf.millions); + bench.end(millions); } diff --git a/benchmark/misc/object-property-bench.js b/benchmark/misc/object-property-bench.js index d6afd4e9c0bcbb..37da82d88758fd 100644 --- a/benchmark/misc/object-property-bench.js +++ b/benchmark/misc/object-property-bench.js @@ -59,10 +59,10 @@ function runSymbol(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) { // '' is a default case for tests case '': case 'property': diff --git a/benchmark/misc/punycode.js b/benchmark/misc/punycode.js index 40bcd70302003c..7016fa11712bbc 100644 --- a/benchmark/misc/punycode.js +++ b/benchmark/misc/punycode.js @@ -62,10 +62,8 @@ function runICU(n, val) { bench.end(n); } -function main(conf) { - const n = +conf.n; - const val = conf.val; - switch (conf.method) { +function main({ n, val, method }) { + switch (method) { // '' is a default case for tests case '': case 'punycode': diff --git a/benchmark/misc/startup.js b/benchmark/misc/startup.js index b010f9fa469070..703146f081b3c6 100644 --- a/benchmark/misc/startup.js +++ b/benchmark/misc/startup.js @@ -8,8 +8,7 @@ const bench = common.createBenchmark(startNode, { dur: [1] }); -function startNode(conf) { - const dur = +conf.dur; +function startNode({ dur }) { var go = true; var starts = 0; diff --git a/benchmark/misc/util-extend-vs-object-assign.js b/benchmark/misc/util-extend-vs-object-assign.js index f2a039bc5d71fc..149619f6e1dea3 100644 --- a/benchmark/misc/util-extend-vs-object-assign.js +++ b/benchmark/misc/util-extend-vs-object-assign.js @@ -8,19 +8,17 @@ const bench = common.createBenchmark(main, { n: [10e4] }); -function main(conf) { +function main({ n, type }) { let fn; - const n = conf.n | 0; - - if (conf.type === 'extend') { + if (type === 'extend') { fn = util._extend; - } else if (conf.type === 'assign') { + } else if (type === 'assign') { fn = Object.assign; } // Force-optimize the method to test so that the benchmark doesn't // get disrupted by the optimizer kicking in halfway through. - for (var i = 0; i < conf.type.length * 10; i += 1) + for (var i = 0; i < type.length * 10; i += 1) fn({}, process.env); const obj = new Proxy({}, { set: function(a, b, c) { return true; } });