forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl-searchparams-inspect.js
More file actions
39 lines (35 loc) · 973 Bytes
/
url-searchparams-inspect.js
File metadata and controls
39 lines (35 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
const common = require('../common.js');
const { inspect } = require('util');
const bench = common.createBenchmark(main, {
variant: ['empty', 'small', 'medium', 'large'],
kind: ['params', 'iterator-keys', 'iterator-values', 'iterator-entries'],
n: [1e5],
});
function makeParams(size) {
const u = new URLSearchParams();
for (let i = 0; i < size; i++) {
u.append('k' + i, 'v' + i);
}
return u;
}
function main({ variant, kind, n }) {
const sizes = { empty: 0, small: 3, medium: 16, large: 128 };
const size = sizes[variant];
const params = makeParams(size);
let target;
if (kind === 'params') {
target = params;
} else if (kind === 'iterator-keys') {
target = params.keys();
} else if (kind === 'iterator-values') {
target = params.values();
} else {
target = params.entries();
}
bench.start();
for (let i = 0; i < n; i++) {
inspect(target, { showHidden: false, depth: 2 });
}
bench.end(n);
}