2-- Module : BenchmarkOps
3-- Copyright : (c) 2018 Harendra Kumar
6-- Maintainer : harendra.kumar@gmail.com
8{-# LANGUAGE ScopedTypeVariables #-}
10module BenchmarkNestedLoopOps where
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.fromFoldable [start..start+n]
34{-# INLINE runStream #-}
35runStream :: Monad m => Stream m a -> m ()
36runStream = S.runStream
38{-# INLINE runToList #-}
39runToList :: Monad m => Stream m a -> m [a]
42-------------------------------------------------------------------------------
44-------------------------------------------------------------------------------
46{-# INLINE toNullLinear #-}
47toNullLinear :: Monad m => Int -> m ()
48toNullLinear start = runStream $ source start sumCount
50{-# INLINE toListLinear #-}
51toListLinear :: Monad m => Int -> m [Int]
52toListLinear start = runToList $ source start sumCount
56 :: (Monoid (t m Int), Monad m, Monad (t m))
57 => (t m Int -> S.SerialT m Int) -> Int -> m ()
58append t start = runStream $ t $ foldMap return [start..start+sumCount]
62 :: (S.IsStream t, Monad m, Monad (t m))
63 => (t m (Int, Int) -> S.SerialT m (Int, Int)) -> Int -> m ()
64toNull0 t start = runStream . t $ do
65 x <- source start prodCount
66 y <- source start prodCount
71 :: (S.IsStream t, Monad m, Monad (t m))
72 => (t m (Int, Int) -> S.SerialT m (Int, Int)) -> Int -> m [(Int, Int)]
73toList0 t start = runToList . t $ do
74 x <- source start prodCount
75 y <- source start prodCount
80 :: (S.IsStream t, Monad m, Monad (t m))
81 => (t m Int -> S.SerialT m Int) -> Int -> m ()
82toNull t start = runStream . t $ do
83 x <- source start prodCount
84 y <- source start prodCount
85 return $ x * x + y * y
89 :: (S.IsStream t, Monad m, Monad (t m))
90 => (t m Int -> S.SerialT m Int) -> Int -> m [Int]
91toList t start = runToList . t $ do
92 x <- source start prodCount
93 y <- source start prodCount
94 return $ x * x + y * y
96{-# INLINE toListSome #-}
98 :: (S.IsStream t, Monad m, Monad (t m))
99 => (t m Int -> S.SerialT m Int) -> Int -> m [Int]
101 runToList . t $ S.take 1000 $ do
102 x <- source start prodCount
103 y <- source start prodCount
104 return $ x * x + y * y
106{-# INLINE filterAllOut #-}
108 :: (S.IsStream t, Monad m, Monad (t m))
109 => (t m Int -> S.SerialT m Int) -> Int -> m ()
110filterAllOut t start = runStream . t $ do
111 x <- source start prodCount
112 y <- source start prodCount
113 let s = x * x + y * y
118{-# INLINE filterAllIn #-}
120 :: (S.IsStream t, Monad m, Monad (t m))
121 => (t m Int -> S.SerialT m Int) -> Int -> m ()
122filterAllIn t start = runStream . t $ do
123 x <- source start prodCount
124 y <- source start prodCount
125 let s = x * x + y * y
130{-# INLINE filterSome #-}
132 :: (S.IsStream t, Monad m, Monad (t m))
133 => (t m Int -> S.SerialT m Int) -> Int -> m ()
134filterSome t start = runStream . t $ do
135 x <- source start prodCount
136 y <- source start prodCount
137 let s = x * x + y * y
142{-# INLINE breakAfterSome #-}
144 :: (S.IsStream t, Monad (t IO))
145 => (t IO Int -> S.SerialT IO Int) -> Int -> IO ()
146breakAfterSome t start = do
147 (_ :: Either ErrorCall ()) <- try $ runStream . t $ do
148 x <- source start prodCount
149 y <- source start prodCount
150 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