Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
benchmark: add more util inspect and format benchmarks
This adds a couple of benchmarks to check different options and code
paths.

PR-URL: #30767
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
BridgeAR committed Jan 20, 2020
commit 2859667b1bcca2238085c6a3ab9ebb4ae9e70224
2 changes: 2 additions & 0 deletions benchmark/util/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const inputs = {
'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, {
Expand Down
18 changes: 13 additions & 5 deletions benchmark/util/inspect-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
const util = require('util');
const common = require('../common.js');

const bench = common.createBenchmark(main, { n: [2e4] });
const bench = common.createBenchmark(main, {
n: [2e4],
showProxy: [0, 1],
isProxy: [0, 1]
});

function main({ n }) {
const proxyA = new Proxy({}, { get: () => {} });
const proxyB = new Proxy(() => {}, {});
function main({ n, showProxy, isProxy }) {
let proxyA = {};
let proxyB = () => {};
if (isProxy) {
proxyA = new Proxy(proxyA, { get: () => {} });
proxyB = new Proxy(proxyB, {});
}
bench.start();
for (let i = 0; i < n; i += 1)
util.inspect({ a: proxyA, b: proxyB }, { showProxy: true });
util.inspect({ a: proxyA, b: proxyB }, { showProxy });
bench.end(n);
}
4 changes: 3 additions & 1 deletion test/benchmark/test-benchmark-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ runBenchmark('util',
'size=1',
'type=',
'len=1',
'version=native'],
'version=native',
'isProxy=1',
'showProxy=1'],
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });