Skip to content

Commit 1e31162

Browse files
committed
Add benchmarks
1 parent acd9a37 commit 1e31162

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

benchmark/Streamly/Benchmark/Prelude/Serial/NestedStream.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,30 @@ joinInnerMap val1 val2 _ =
436436
(fmap toKvMap (mkStreamLen val1))
437437
(fmap toKvMap (mkStreamLen val2))
438438

439+
{-# INLINE intersectBy #-}
440+
intersectBy :: Int -> Int -> Int -> IO ()
441+
intersectBy val1 val2 _ =
442+
S.drain $
443+
Internal.intersectBy (==)
444+
(fmap toKvMap (mkStreamLen val1))
445+
(fmap toKvMap (mkStreamLen val2))
446+
447+
{-# INLINE intersectBySorted #-}
448+
intersectBySorted :: Int -> Int -> Int -> IO ()
449+
intersectBySorted val1 val2 _ =
450+
S.drain $
451+
Internal.intersectBySorted compare
452+
(fmap toKvMap (mkStreamLen val1))
453+
(fmap toKvMap (mkStreamLen val2))
454+
439455
o_n_heap_buffering :: Int -> [Benchmark]
440456
o_n_heap_buffering value =
441457
[ bgroup "buffered"
442458
[
443459
benchIOSrc1 "joinInner" (joinInner sqrtVal sqrtVal)
444460
, benchIOSrc1 "joinInnerMap" (joinInnerMap sqrtVal sqrtVal)
461+
, benchIOSrc1 "intersectBy" (intersectBy sqrtVal sqrtVal)
462+
, benchIOSrc1 "intersectBySorted" (intersectBySorted sqrtVal sqrtVal)
445463
]
446464
]
447465

test/Streamly/Test/Prelude/Top.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ joinInnerMap =
6666
]
6767
assert (v1 == v2)
6868

69+
intersectBy :: Property
70+
intersectBy =
71+
forAll (listOf (chooseInt (min_value, max_value))) $ \ls0 ->
72+
forAll (listOf (chooseInt (min_value, max_value))) $ \ls1 ->
73+
monadicIO $ action (sort ls0) (sort ls1)
74+
75+
where
76+
77+
action ls0 ls1 = do
78+
v1 <-
79+
run
80+
$ S.toList
81+
$ Top.intersectBy
82+
(==)
83+
(S.fromList ls0)
84+
(S.fromList ls1)
85+
let v2 = intersect ls0 ls1
86+
assert (v1 == sort v2)
87+
6988
intersectBySorted :: Property
7089
intersectBySorted =
7190
forAll (listOf (chooseInt (min_value, max_value))) $ \ls0 ->
@@ -97,4 +116,5 @@ main = hspec $ do
97116
prop "joinInner" Main.joinInner
98117
prop "joinInnerMap" Main.joinInnerMap
99118
-- intersect
119+
prop "intersectBy" Main.intersectBy
100120
prop "intersectBySorted" Main.intersectBySorted

0 commit comments

Comments
 (0)