Skip to content

Commit 328ae5f

Browse files
committed
Add concat to benchmark
1 parent d068679 commit 328ae5f

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

benchmark/misc/console.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ const v8 = require('v8');
99
v8.setFlagsFromString('--allow_natives_syntax');
1010

1111
var bench = common.createBenchmark(main, {
12-
method: ['restAndSpread', 'argumentsAndApply', 'restAndApply'],
12+
method: ['restAndSpread',
13+
'argumentsAndApply',
14+
'restAndApply',
15+
'restAndConcat'],
1316
concat: [1, 0],
1417
n: [1000000]
1518
});
1619

1720
const nullStream = createNullStream();
1821

22+
function usingRestAndConcat(...args) {
23+
nullStream.write('this is ' + args[0] + ' of ' + args[1] + '\n');
24+
}
25+
1926
function usingRestAndSpreadTS(...args) {
2027
nullStream.write(`${util.format(...args)}\n`);
2128
}
@@ -46,6 +53,16 @@ function optimize(method, ...args) {
4653
method(...args);
4754
}
4855

56+
function runUsingRestAndConcat(n) {
57+
optimize(usingRestAndConcat, 'a', 1);
58+
59+
var i = 0;
60+
bench.start();
61+
for (; i < n; i++)
62+
usingRestAndConcat('a', 1);
63+
bench.end(n);
64+
}
65+
4966
function runUsingRestAndSpread(n, concat) {
5067

5168
const method = concat ? usingRestAndSpreadC : usingRestAndSpreadTS;
@@ -89,11 +106,15 @@ function main(conf) {
89106
runUsingRestAndSpread(n, conf.concat);
90107
break;
91108
case 'restAndApply':
92-
runUsingRestAndApply(n);
109+
runUsingRestAndApply(n, conf.concat);
93110
break;
94111
case 'argumentsAndApply':
95-
runUsingArgumentsAndApply(n);
112+
runUsingArgumentsAndApply(n, conf.concat);
96113
break;
114+
case 'restAndConcat':
115+
if (conf.concat)
116+
runUsingRestAndConcat(n);
117+
break;
97118
default:
98119
throw new Error('Unexpected method');
99120
}

0 commit comments

Comments
 (0)