-
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
import { bench, run, group } from "mitata";
const SET_SIZE = 100_000;
/**
* @param size {number}
* @returns {Set<{ n: number }>}
*/
function sampleSet(size) {
return new Set(Array.from({ length: size }, (_, i) => ({ n: i })));
}
group(`a.size = ${SET_SIZE}`, () => {
bench("for (const x of a) { a.delete(x) }", () => {
const a = sampleSet(SET_SIZE);
for (const x of a) {
a.delete(x);
}
});
bench("a.clear()", () => {
const a = sampleSet(SET_SIZE);
a.clear();
});
});
await run();