2-- Module : BenchmarkOps
3-- Copyright : (c) 2018 Harendra Kumar
6-- Maintainer : harendra.kumar@gmail.com
8{-# LANGUAGE ScopedTypeVariables #-}
12import Control.Exception (try)
13import GHC.Exception (ErrorCall)
15import qualified Streamly as S
16import qualified Streamly.Prelude as S
24-------------------------------------------------------------------------------
25-- Stream generation and elimination
26-------------------------------------------------------------------------------
28type Stream m a = S.SerialT m a
31source :: S.IsStream t => Int -> Int -> t m Int
32source start n = S.unfoldr step start
37 else (Just (cnt, cnt + 1))
39{-# INLINE runStream #-}
40runStream :: Monad m => Stream m a -> m ()
41runStream = S.runStream
43{-# INLINE runToList #-}
44runToList :: Monad m => Stream m a -> m [a]
47-------------------------------------------------------------------------------
49-------------------------------------------------------------------------------
51{-# INLINE toNullLinear #-}
52toNullLinear :: Monad m => Int -> m ()
53toNullLinear start = runStream $ source start sumCount
55{-# INLINE toListLinear #-}
56toListLinear :: Monad m => Int -> m [Int]
57toListLinear start = runToList $ source start sumCount
61 :: (Monoid (t m Int), Monad m, Monad (t m))
62 => (t m Int -> S.SerialT m Int) -> Int -> m ()
63append t start = runStream $ t $ foldMap return [start..start+sumCount]
67 :: (S.IsStream t, Monad m, Monad (t m))
68 => (t m (Int, Int) -> S.SerialT m (Int, Int)) -> Int -> m ()
69toNull0 t start = runStream . t $ do
70 x <- source start prodCount
71 y <- source start prodCount
76 :: (S.IsStream t, Monad m, Monad (t m))
77 => (t m (Int, Int) -> S.SerialT m (Int, Int)) -> Int -> m [(Int, Int)]
78toList0 t start = runToList . t $ do
79 x <- source start prodCount
80 y <- source start prodCount
85 :: (S.IsStream t, Monad m, Monad (t m))
86 => (t m Int -> S.SerialT m Int) -> Int -> m ()
87toNull t start = runStream . t $ do
88 x <- source start prodCount
89 y <- source start prodCount
90 return $ x * x + y * y
94 :: (S.IsStream t, Monad m, Monad (t m))
95 => (t m Int -> S.SerialT m Int) -> Int -> m [Int]
96toList t start = runToList . t $ do
97 x <- source start prodCount
98 y <- source start prodCount
99 return $ x * x + y * y
101{-# INLINE toListSome #-}
103 :: (S.IsStream t, Monad m, Monad (t m))
104 => (t m Int -> S.SerialT m Int) -> Int -> m [Int]
106 runToList . t $ S.take 1000 $ do
107 x <- source start prodCount
108 y <- source start prodCount
109 return $ x * x + y * y
111{-# INLINE filterAllOut #-}
113 :: (S.IsStream t, Monad m, Monad (t m))
114 => (t m Int -> S.SerialT m Int) -> Int -> m ()
115filterAllOut t start = runStream . t $ do
116 x <- source start prodCount
117 y <- source start prodCount
118 let s = x * x + y * y
123{-# INLINE filterAllIn #-}
125 :: (S.IsStream t, Monad m, Monad (t m))
126 => (t m Int -> S.SerialT m Int) -> Int -> m ()
127filterAllIn t start = runStream . t $ do
128 x <- source start prodCount
129 y <- source start prodCount
130 let s = x * x + y * y
135{-# INLINE filterSome #-}
137 :: (S.IsStream t, Monad m, Monad (t m))
138 => (t m Int -> S.SerialT m Int) -> Int -> m ()
139filterSome t start = runStream . t $ do
140 x <- source start prodCount
141 y <- source start prodCount
142 let s = x * x + y * y
147{-# INLINE breakAfterSome #-}
149 :: (S.IsStream t, Monad (t IO))
150 => (t IO Int -> S.SerialT IO Int) -> Int -> IO ()
151breakAfterSome t start = do
152 (_ :: Either ErrorCall ()) <- try $ runStream . t $ do
153 x <- source start prodCount
154 y <- source start prodCount
155 let s = x * x + y * y
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