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
29nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
33nestedCount3 = round (fromIntegral linearCount**(1/3::Double))
35-------------------------------------------------------------------------------
36-- Stream generation and elimination
37-------------------------------------------------------------------------------
39type Stream m a = S.SerialT m a
42source :: (S.MonadAsync m, S.IsStream t) => Int -> Int -> t m Int
43source = sourceUnfoldrM
45{-# INLINE sourceUnfoldrM #-}
46sourceUnfoldrM :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m Int
47sourceUnfoldrM n value = S.serially $ S.unfoldrM step n
52 else return (Just (cnt, cnt + 1))
54{-# INLINE sourceUnfoldr #-}
55sourceUnfoldr :: (Monad m, S.IsStream t) => Int -> Int -> t m Int
56sourceUnfoldr start n = S.unfoldr step start
61 else Just (cnt, cnt + 1)
63{-# INLINE runStream #-}
64runStream :: Monad m => Stream m a -> m ()
67{-# INLINE runToList #-}
68runToList :: Monad m => Stream m a -> m [a]
71-------------------------------------------------------------------------------
73-------------------------------------------------------------------------------
75{-# INLINE toNullAp #-}
77 :: (S.IsStream t, S.MonadAsync m, Applicative (t m))
78 => (t m Int -> S.SerialT m Int) -> Int -> m ()
79toNullAp t start = runStream . t $
80 (+) <$> source start nestedCount2 <*> source start nestedCount2
84 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
85 => (t m Int -> S.SerialT m Int) -> Int -> m ()
86toNull t start = runStream . t $ do
87 x <- source start nestedCount2
88 y <- source start nestedCount2
93 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
94 => (t m Int -> S.SerialT m Int) -> Int -> m ()
95toNull3 t start = runStream . t $ do
96 x <- source start nestedCount3
97 y <- source start nestedCount3
98 z <- source start nestedCount3
103 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
104 => (t m Int -> S.SerialT m Int) -> Int -> m [Int]
105toList t start = runToList . t $ do
106 x <- source start nestedCount2
107 y <- source start nestedCount2
110{-# INLINE toListSome #-}
112 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
113 => (t m Int -> S.SerialT m Int) -> Int -> m [Int]
115 runToList . t $ S.take 1000 $ do
116 x <- source start nestedCount2
117 y <- source start nestedCount2
120{-# INLINE filterAllOut #-}
122 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
123 => (t m Int -> S.SerialT m Int) -> Int -> m ()
124filterAllOut t start = runStream . t $ do
125 x <- source start nestedCount2
126 y <- source start nestedCount2
132{-# INLINE filterAllIn #-}
134 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
135 => (t m Int -> S.SerialT m Int) -> Int -> m ()
136filterAllIn t start = runStream . t $ do
137 x <- source start nestedCount2
138 y <- source start nestedCount2
144{-# INLINE filterSome #-}
146 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
147 => (t m Int -> S.SerialT m Int) -> Int -> m ()
148filterSome t start = runStream . t $ do
149 x <- source start nestedCount2
150 y <- source start nestedCount2
156{-# INLINE breakAfterSome #-}
158 :: (S.IsStream t, Monad (t IO))
159 => (t IO Int -> S.SerialT IO Int) -> Int -> IO ()
160breakAfterSome t start = do
161 (_ :: Either ErrorCall ()) <- try $ runStream . t $ do
162 x <- source start nestedCount2
163 y <- source start nestedCount2
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