diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2017-09-15 21:56:53 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-09-21 17:52:54 +0300 |
commit | fc1448f35737d88c14fd41491af704c933eca6c2 (patch) | |
tree | ba12ae5e09dfa0631e3dd0d332411c99597d20e5 /benchmark | |
parent | 4f7d9392e7f9405999533c21113aeebe433ecd94 (diff) |
util: improve format performance
PR-URL: https://github.com/nodejs/node/pull/15422
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/util/format.js | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/benchmark/util/format.js b/benchmark/util/format.js index 00b59519dfd..6f171318ee2 100644 --- a/benchmark/util/format.js +++ b/benchmark/util/format.js @@ -2,35 +2,30 @@ const util = require('util'); const common = require('../common'); -const types = [ - 'string', - 'number', - 'object', - 'unknown', - 'no-replace' -]; -const bench = common.createBenchmark(main, { - n: [2e6], - type: types -}); const inputs = { - 'string': ['Hello, my name is %s', 'fred'], - 'number': ['Hi, I was born in %d', 1942], - 'object': ['An error occurred %j', { msg: 'This is an error', code: 'ERR' }], + 'string': ['Hello, my name is %s', 'Fred'], + 'string-2': ['Hello, %s is my name', 'Fred'], + 'number': ['Hi, I was born in %d', 1989], + 'replace-object': ['An error occurred %j', { msg: 'This is an error' }], 'unknown': ['hello %a', 'test'], - 'no-replace': [1, 2] + 'no-replace': [1, 2], + 'no-replace-2': ['foobar', 'yeah', 'mensch', 5], + 'only-objects': [{ msg: 'This is an error' }, { msg: 'This is an error' }], + 'many-%': ['replace%%%%s%%%%many%s%s%s', 'percent'], }; -function main(conf) { - const n = conf.n | 0; - const type = conf.type; +const bench = common.createBenchmark(main, { + n: [4e6], + type: Object.keys(inputs) +}); - const input = inputs[type]; +function main({ n, type }) { + const [first, second] = inputs[type]; bench.start(); for (var i = 0; i < n; i++) { - util.format(input[0], input[1]); + util.format(first, second); } bench.end(n); } |