Skip to content

Commit 1a4cda9

Browse files
committed
chore: Add nested loop benchmarks
1 parent b5bd100 commit 1a4cda9

File tree

1 file changed

+56
-31
lines changed

1 file changed

+56
-31
lines changed

benchmark/issue25.js

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,72 @@ function ForEachBench() {
1414
console.log("starting forEach benchmark");
1515
const tb = new TypedFastBitSet();
1616
const stb = new SparseTypedFastBitSet();
17+
const tb_small = new TypedFastBitSet();
1718

1819
const s = new Set();
1920
for (let i = 0; i < N; i++) {
21+
if (i < 100) {
22+
tb_small.add(i);
23+
}
2024
tb.add(smallgap * i + 5);
2125
stb.add(smallgap * i + 5);
2226
}
2327

2428
const suite = new Benchmark.Suite();
2529
// add tests
2630
const ms = suite
27-
.add("TypedFastBitSet-forof", function () {
28-
let card = 0;
29-
for (const element of stb) {
30-
card++;
31-
}
32-
return card;
33-
})
34-
.add("TypedFastBitSet-foreach", function () {
35-
let card = 0;
36-
const inc = function () {
37-
card++;
38-
};
39-
tb.forEach(inc);
40-
return card;
41-
})
42-
.add("SparseTypedFastBitSet-forof", function () {
43-
let card = 0;
44-
for (const element of stb) {
45-
card++;
46-
}
47-
return card;
48-
})
49-
.add("SparseTypedFastBitSet-foreach", function () {
50-
let card = 0;
51-
const inc = function () {
52-
card++;
53-
};
54-
tb.forEach(inc);
55-
return card;
56-
})
31+
.add("TypedFastBitSet-forof", function () {
32+
let card = 0;
33+
for (const element of stb) {
34+
card++;
35+
}
36+
return card;
37+
})
38+
.add("TypedFastBitSet-foreach", function () {
39+
let card = 0;
40+
const inc = function () {
41+
card++;
42+
};
43+
tb.forEach(inc);
44+
return card;
45+
})
46+
.add("SparseTypedFastBitSet-forof", function () {
47+
let card = 0;
48+
for (const element of stb) {
49+
card++;
50+
}
51+
return card;
52+
})
53+
.add("SparseTypedFastBitSet-foreach", function () {
54+
let card = 0;
55+
const inc = function () {
56+
card++;
57+
};
58+
tb.forEach(inc);
59+
return card;
60+
})
61+
.add("TypedFastBitSet-nested-forof", function () {
62+
let card = 0;
63+
for (const x of tb_small) {
64+
for (const y of tb_small) {
65+
for (const z of tb_small) {
66+
card += x + y + z;
67+
}
68+
}
69+
}
70+
return card;
71+
})
72+
.add("TypedFastBitSet-nested-forEach", function () {
73+
let card = 0;
74+
tb_small.forEach(function (x) {
75+
tb_small.forEach(function (y) {
76+
tb_small.forEach(function (z) {
77+
card += x + y + z;
78+
});
79+
});
80+
});
81+
return card;
82+
})
5783
// add listeners
5884
.on("cycle", function (event) {
5985
console.log(String(event.target));
@@ -62,7 +88,6 @@ function ForEachBench() {
6288
.run({ async: false });
6389
}
6490

65-
6691
const main = function () {
6792
console.log(
6893
"Platform: " + process.platform + " " + os.release() + " " + process.arch

0 commit comments

Comments
 (0)