Skip to content

Commit b04f3ed

Browse files
committed
Add benchmarks for intersection
1 parent e24fbac commit b04f3ed

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

benchmarks/FineGrained.hs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ main =
3232
bInsert,
3333
bDelete,
3434
bUnion,
35+
bIntersection,
3536
bDifference
3637
],
3738
bgroup "HashSet" [bSetFromList]
@@ -262,6 +263,42 @@ bUnionEqual =
262263
where
263264
b size = bench (show size) . whnf (\m -> HM.union m m)
264265

266+
-- TODO: For the "overlap" and "equal" cases, it would be interesting to
267+
-- have separate benchmarks both with and without shared subtrees,
268+
-- so we can make use of pointer equality.
269+
bIntersection :: Benchmark
270+
bIntersection =
271+
bgroup
272+
"intersection"
273+
[ bgroup "disjoint" bIntersectionDisjoint,
274+
bgroup "overlap" bIntersectionOverlap,
275+
bgroup "equal" bIntersectionEqual
276+
]
277+
278+
bIntersectionDisjoint :: [Benchmark]
279+
bIntersectionDisjoint =
280+
[ bgroup' "Bytes" genBytesMapsDisjoint b,
281+
bgroup' "Int" genIntMapsDisjoint b
282+
]
283+
where
284+
b size = bench (show size) . whnf (\(xs, ys) -> HM.intersection xs ys)
285+
286+
bIntersectionOverlap :: [Benchmark]
287+
bIntersectionOverlap =
288+
[ bgroup' "Bytes" genBytesMapsOverlap b,
289+
bgroup' "Int" genIntMapsOverlap b
290+
]
291+
where
292+
b size = bench (show size) . whnf (\(xs, ys) -> HM.intersection xs ys)
293+
294+
bIntersectionEqual :: [Benchmark]
295+
bIntersectionEqual =
296+
[ bgroup' "Bytes" genBytesMap b,
297+
bgroup' "Int" genIntMap b
298+
]
299+
where
300+
b size = bench (show size) . whnf (\m -> HM.intersection m m)
301+
265302
-- TODO: For the "overlap" and "equal" cases, it would be interesting to
266303
-- have separate benchmarks both with and without shared subtrees,
267304
-- so we can make use of pointer equality.

0 commit comments

Comments
 (0)