0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/util/format.js
Sebastiaan Deckers bb29405904
lib,src: fix consistent spacing inside braces
PR-URL: https://github.com/nodejs/node/pull/14162
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-21 15:13:47 -04:00

37 lines
702 B
JavaScript

'use strict';
const util = require('util');
const common = require('../common');
const types = [
'string',
'number',
'object',
'unknown',
'no-replace'
];
const bench = common.createBenchmark(main, {
n: [1e6],
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' }],
'unknown': ['hello %a', 'test'],
'no-replace': [1, 2]
};
function main(conf) {
const n = conf.n | 0;
const type = conf.type;
const input = inputs[type];
bench.start();
for (var i = 0; i < n; i++) {
util.format(input[0], input[1]);
}
bench.end(n);
}