File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
benchmark/Streamly/Benchmark/Prelude/Serial
test/Streamly/Test/Prelude Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff 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+
439455o_n_heap_buffering :: Int -> [Benchmark ]
440456o_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
Original file line number Diff line number Diff 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+
6988intersectBySorted :: Property
7089intersectBySorted =
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
You can’t perform that action at this time.
0 commit comments