Skip to content

Commit

Permalink
benchmark: (es) use destructuring
Browse files Browse the repository at this point in the history
PR-URL: nodejs#18250
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR authored and MayaLekova committed May 8, 2018
1 parent 3066a35 commit baca352
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 36 deletions.
6 changes: 3 additions & 3 deletions benchmark/es/defaultparams-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
6 changes: 3 additions & 3 deletions benchmark/es/destructuring-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
6 changes: 3 additions & 3 deletions benchmark/es/destructuring-object-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
8 changes: 3 additions & 5 deletions benchmark/es/foreach-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
6 changes: 3 additions & 3 deletions benchmark/es/map-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
6 changes: 3 additions & 3 deletions benchmark/es/restparams-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
14 changes: 7 additions & 7 deletions benchmark/es/spread-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
6 changes: 2 additions & 4 deletions benchmark/es/string-concatenations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
8 changes: 3 additions & 5 deletions benchmark/es/string-repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit baca352

Please sign in to comment.