mirror of
https://github.com/nodejs/node.git
synced 2024-11-24 12:10:08 +01:00
b2f23f0bd0
Fixes: https://github.com/nodejs/node/issues/50571 PR-URL: https://github.com/nodejs/node/pull/50932 Refs: https://github.com/nodejs/node/issues/50571 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
34 lines
950 B
JavaScript
34 lines
950 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'],
|
|
'object-to-string': ['foo %s bar', { toString() { return 'bla'; } }],
|
|
'object-%s': ['foo %s bar', { a: true, b: false }],
|
|
};
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
n: [1e6],
|
|
type: Object.keys(inputs),
|
|
});
|
|
|
|
function main({ n, type }) {
|
|
const [first, second] = inputs[type];
|
|
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
util.format(first, second);
|
|
}
|
|
bench.end(n);
|
|
}
|