Skip to content

Commit

Permalink
Add concat to benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Apr 19, 2016
1 parent d068679 commit 328ae5f
Showing 1 changed file with 24 additions and 3 deletions.
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

0 comments on commit 328ae5f

Please sign in to comment.