-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathurl-searchparams-mutation.js
More file actions
43 lines (36 loc) · 956 Bytes
/
url-searchparams-mutation.js
File metadata and controls
43 lines (36 loc) · 956 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
40
41
42
43
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
method: ['set', 'delete'],
type: ['unique', 'duplicates'],
count: [10, 1000],
n: [1e4],
});
function buildSeed(type, count) {
const parts = new Array(count);
if (type === 'duplicates') {
for (let i = 0; i < count; i++) {
parts[i] = `dup=${i}`;
}
} else {
for (let i = 0; i < count; i++) {
parts[i] = `k${i}=${i}`;
}
}
return new URLSearchParams(parts.join('&'));
}
function main({ method, type, count, n }) {
const seed = buildSeed(type, count);
const key = type === 'duplicates' ? 'dup' : 'k0';
const mutate = method === 'set' ?
(params) => params.set(key, 'updated') :
(params) => params.delete(key);
for (let i = 0; i < 1e3; i++) {
mutate(new URLSearchParams(seed));
}
bench.start();
for (let i = 0; i < n; i++) {
mutate(new URLSearchParams(seed));
}
bench.end(n);
}