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{-# INLINE toListSome #-}
106 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
107 => Int -> (t m Int -> S.SerialT m Int) -> Int -> m [Int]
108toListSome linearCount t start =
109 runToList . t $ S.take 1000 $ do
110 x <- source start nestedCount2
111 y <- source start nestedCount2
114 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
116{-# INLINE filterAllOut #-}
118 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
119 => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
120filterAllOut linearCount t start = runStream . t $ do
121 x <- source start nestedCount2
122 y <- source start nestedCount2
128 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
130{-# INLINE filterAllIn #-}
132 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
133 => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
134filterAllIn linearCount t start = runStream . t $ do
135 x <- source start nestedCount2
136 y <- source start nestedCount2
142 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
144{-# INLINE filterSome #-}
146 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
147 => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
148filterSome linearCount t start = runStream . t $ do
149 x <- source start nestedCount2
150 y <- source start nestedCount2
156 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
158{-# INLINE breakAfterSome #-}
160 :: (S.IsStream t, Monad (t IO))
161 => Int -> (t IO Int -> S.SerialT IO Int) -> Int -> IO ()
162breakAfterSome linearCount t start = do
163 (_ :: Either ErrorCall ()) <- try $ runStream . t $ do
164 x <- source start nestedCount2
165 y <- source start nestedCount2
172 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