Skip to content
Closed
Changes from 1 commit
Commits
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
Prev Previous commit
Add concat to benchmark
  • Loading branch information
jasnell committed Apr 19, 2016
commit 328ae5fde6084912e04ddf370215a1d7384c27bf
27 changes: 24 additions & 3 deletions benchmark/misc/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ const v8 = require('v8');
v8.setFlagsFromString('--allow_natives_syntax');

var bench = common.createBenchmark(main, {
method: ['restAndSpread', 'argumentsAndApply', 'restAndApply'],
method: ['restAndSpread',
'argumentsAndApply',
'restAndApply',
'restAndConcat'],
concat: [1, 0],
n: [1000000]
});

const nullStream = createNullStream();

function usingRestAndConcat(...args) {
nullStream.write('this is ' + args[0] + ' of ' + args[1] + '\n');
}

function usingRestAndSpreadTS(...args) {
nullStream.write(`${util.format(...args)}\n`);
}
Expand Down Expand Up @@ -46,6 +53,16 @@ function optimize(method, ...args) {
method(...args);
}

function runUsingRestAndConcat(n) {
optimize(usingRestAndConcat, 'a', 1);

var i = 0;
bench.start();
for (; i < n; i++)
usingRestAndConcat('a', 1);
bench.end(n);
}

function runUsingRestAndSpread(n, concat) {

const method = concat ? usingRestAndSpreadC : usingRestAndSpreadTS;
Expand Down Expand Up @@ -89,11 +106,15 @@ function main(conf) {
runUsingRestAndSpread(n, conf.concat);
break;
case 'restAndApply':
runUsingRestAndApply(n);
runUsingRestAndApply(n, conf.concat);
break;
case 'argumentsAndApply':
runUsingArgumentsAndApply(n);
runUsingArgumentsAndApply(n, conf.concat);
break;
case 'restAndConcat':
if (conf.concat)
runUsingRestAndConcat(n);
break;
default:
throw new Error('Unexpected method');
}
Expand Down