diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2017-12-16 01:33:56 -0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2017-12-20 01:33:50 -0300 |
commit | 0eab49523d75235cbd14047da5b74467596ae590 (patch) | |
tree | 04e3f1f38d383b8f1a77433a5f9e416c5582e63b /benchmark/misc/arguments.js | |
parent | 1d6b729cea909769ac0bcb3aa68f5fe567c4ffb7 (diff) | |
download | android-node-v8-0eab49523d75235cbd14047da5b74467596ae590.tar.gz android-node-v8-0eab49523d75235cbd14047da5b74467596ae590.tar.bz2 android-node-v8-0eab49523d75235cbd14047da5b74467596ae590.zip |
benchmark: refactor console benchmark
Fix and refactor the console benchmark. It did not test console
so it got renamed and mainly tests the different ways of passing
arguments through.
PR-URL: https://github.com/nodejs/node/pull/17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark/misc/arguments.js')
-rw-r--r-- | benchmark/misc/arguments.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/benchmark/misc/arguments.js b/benchmark/misc/arguments.js new file mode 100644 index 0000000000..2e5df6188b --- /dev/null +++ b/benchmark/misc/arguments.js @@ -0,0 +1,59 @@ +'use strict'; + +const { createBenchmark } = require('../common.js'); +const { format } = require('util'); + +const methods = [ + 'restAndSpread', + 'argumentsAndApply', + 'restAndApply', + 'predefined' +]; + +const bench = createBenchmark(main, { + method: methods, + n: [1e6] +}); + +function usingRestAndSpread(...args) { + format(...args); +} + +function usingRestAndApply(...args) { + format.apply(null, args); +} + +function usingArgumentsAndApply() { + format.apply(null, arguments); +} + +function usingPredefined() { + format('part 1', 'part', 2, 'part 3', 'part', 4); +} + +function main({ n, method, args }) { + var fn; + switch (method) { + // '' is a default case for tests + case '': + case 'restAndSpread': + fn = usingRestAndSpread; + break; + case 'restAndApply': + fn = usingRestAndApply; + break; + case 'argumentsAndApply': + fn = usingArgumentsAndApply; + break; + case 'predefined': + fn = usingPredefined; + break; + default: + throw new Error(`Unexpected method "${method}"`); + } + + bench.start(); + for (var i = 0; i < n; i++) + fn('part 1', 'part', 2, 'part 3', 'part', 4); + bench.end(n); +} |