2-- Module : BenchmarkOps
3-- Copyright : (c) 2018 Harendra Kumar
6-- Maintainer : streamly@composewell.com
9{-# LANGUAGE FlexibleContexts #-}
10{-# LANGUAGE ScopedTypeVariables #-}
14import Control.Exception (try)
15import GHC.Exception (ErrorCall)
17import qualified Streamly as S hiding (runStream)
18import qualified Streamly.Prelude as S
20-------------------------------------------------------------------------------
21-- Stream generation and elimination
22-------------------------------------------------------------------------------
24type Stream m a = S.SerialT m a
27source :: (S.MonadAsync m, S.IsStream t) => Int -> Int -> t m Int
28source = sourceUnfoldrM
30-- Change this to "sourceUnfoldrM value n" for consistency
31{-# INLINE sourceUnfoldrM #-}
32sourceUnfoldrM :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m Int
33sourceUnfoldrM n value = S.serially $ S.unfoldrM step n
38 else return (Just (cnt, cnt + 1))
40{-# INLINE sourceUnfoldr #-}
41sourceUnfoldr :: (Monad m, S.IsStream t) => Int -> Int -> t m Int
42sourceUnfoldr start n = S.unfoldr step start
47 else Just (cnt, cnt + 1)
49{-# INLINE runStream #-}
50runStream :: Monad m => Stream m a -> m ()
53{-# INLINE runToList #-}
54runToList :: Monad m => Stream m a -> m [a]
57-------------------------------------------------------------------------------
59-------------------------------------------------------------------------------
61{-# INLINE toNullAp #-}
63 :: (S.IsStream t, S.MonadAsync m, Applicative (t m))
64 => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
65toNullAp linearCount t start = runStream . t $
66 (+) <$> source start nestedCount2 <*> source start nestedCount2
68 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
72 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
73 => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
74toNull linearCount t start = runStream . t $ do
75 x <- source start nestedCount2
76 y <- source start nestedCount2
79 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
83 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
84 => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
85toNull3 linearCount t start = runStream . t $ do
86 x <- source start nestedCount3
87 y <- source start nestedCount3
88 z <- source start nestedCount3
91 nestedCount3 = round (fromIntegral linearCount**(1/3::Double))
95 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
96 => Int -> (t m Int -> S.SerialT m Int) -> Int -> m [Int]
97toList linearCount t start = runToList . t $ do
98 x <- source start nestedCount2
99 y <- source start nestedCount2
102 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
104-- Taking a specified number of elements is very expensive in logict so we have
105-- a test to measure the same.
106{-# INLINE toListSome #-}
108 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
109 => Int -> (t m Int -> S.SerialT m Int) -> Int -> m [Int]
110toListSome linearCount t start =
111 runToList . t $ S.take 10000 $ do
112 x <- source start nestedCount2
113 y <- source start nestedCount2
116 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
118{-# INLINE filterAllOut #-}
120 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
121 => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
122filterAllOut linearCount t start = runStream . t $ do
123 x <- source start nestedCount2
124 y <- source start nestedCount2
130 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
132{-# INLINE filterAllIn #-}
134 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
135 => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
136filterAllIn linearCount t start = runStream . t $ do
137 x <- source start nestedCount2
138 y <- source start nestedCount2
144 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
146{-# INLINE filterSome #-}
148 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
149 => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
150filterSome linearCount t start = runStream . t $ do
151 x <- source start nestedCount2
152 y <- source start nestedCount2
158 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
160{-# INLINE breakAfterSome #-}
162 :: (S.IsStream t, Monad (t IO))
163 => Int -> (t IO Int -> S.SerialT IO Int) -> Int -> IO ()
164breakAfterSome linearCount t start = do
165 (_ :: Either ErrorCall ()) <- try $ runStream . t $ do
166 x <- source start nestedCount2
167 y <- source start nestedCount2
174 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list