From 328ae5fde6084912e04ddf370215a1d7384c27bf Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 19 Apr 2016 11:52:20 -0700 Subject: [PATCH] Add concat to benchmark --- benchmark/misc/console.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/benchmark/misc/console.js b/benchmark/misc/console.js index e26d8dbf351d20..d352943e80dd87 100644 --- a/benchmark/misc/console.js +++ b/benchmark/misc/console.js @@ -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`); } @@ -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; @@ -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'); }