0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/benchmark/util/format.js
Alex Ramirez d349ba29ef benchmark: swap var for let in util benchmarks
In benchmark util directory this changes for loops using var to let
when it applies for consistency

PR-URL: https://github.com/nodejs/node/pull/28867
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-07-30 09:38:00 -07:00

33 lines
904 B
JavaScript

'use strict';
const util = require('util');
const common = require('../common');
const inputs = {
'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-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'],
};
const bench = common.createBenchmark(main, {
n: [1e5],
type: Object.keys(inputs)
});
function main({ n, type }) {
// For testing, if supplied with an empty type, default to string.
const [first, second] = inputs[type || 'string'];
bench.start();
for (let i = 0; i < n; i++) {
util.format(first, second);
}
bench.end(n);
}