mirror of
https://github.com/nodejs/node.git
synced 2025-05-11 17:55:31 +00:00

Some of the benchmark code can be a little dense. Not *very* hard to read but perhaps harder than it needs to be. These changes (many of them whitespace-only) hopefully improve readability. There are also a few cases of `assert.equal()` that are changed to `assert.strictEqual()`. PR-URL: https://github.com/nodejs/node/pull/9790 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
44 lines
901 B
JavaScript
44 lines
901 B
JavaScript
'use strict';
|
|
|
|
const util = require('util');
|
|
const common = require('../common');
|
|
const v8 = require('v8');
|
|
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];
|
|
|
|
v8.setFlagsFromString('--allow_natives_syntax');
|
|
|
|
util.format(input[0], input[1]);
|
|
eval('%OptimizeFunctionOnNextCall(util.format)');
|
|
util.format(input[0], input[1]);
|
|
|
|
bench.start();
|
|
for (var i = 0; i < n; i++) {
|
|
util.format(input[0], input[1]);
|
|
}
|
|
bench.end(n);
|
|
}
|