summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2017-09-15 15:56:53 -0300
committerRuben Bridgewater <ruben@bridgewater.de>2017-09-19 20:05:27 -0300
commitfaaefa8082033809246d004a9c46b0a612c3bb99 (patch)
tree58a6ae40961be6284f6963385cfb5aa116418d8e /benchmark
parent6f340762d8296902de079208bd55bf7118814db7 (diff)
downloadnode-new-faaefa8082033809246d004a9c46b0a612c3bb99.tar.gz
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.js35
1 files changed, 15 insertions, 20 deletions
diff --git a/benchmark/util/format.js b/benchmark/util/format.js
index 00b59519df..6f171318ee 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);
}