2-- Module : Streamly.Benchmark.Data.SmallArrayOps
3-- Copyright : (c) 2019 Composewell Technologies
5-- License : BSD-3-Clause
6-- Maintainer : streamly@composewell.com
7-- Stability : experimental
11{-# LANGUAGE DeriveAnyClass #-}
12{-# LANGUAGE DeriveGeneric #-}
13{-# LANGUAGE FlexibleContexts #-}
14{-# LANGUAGE ScopedTypeVariables #-}
16module Streamly.Benchmark.Data.SmallArrayOps where
18import Control.Monad.IO.Class (MonadIO)
19import Prelude (Int, Bool, (+), ($), (==), (>), (.), Maybe(..), undefined)
20import qualified Prelude as P
22import qualified Data.Foldable as F
25import qualified Streamly as S hiding (foldMapWith, runStream)
26import qualified Streamly.Data.SmallArray as A
27import qualified Streamly.Prelude as S
32-------------------------------------------------------------------------------
34-------------------------------------------------------------------------------
36-------------------------------------------------------------------------------
37-- Stream generation and elimination
38-------------------------------------------------------------------------------
40type Stream = A.SmallArray
42{-# INLINE sourceUnfoldr #-}
43sourceUnfoldr :: MonadIO m => Int -> m (Stream Int)
44sourceUnfoldr n = S.fold (A.writeN value) $ S.unfoldr step n
49 else (Just (cnt, cnt + 1))
51{-# INLINE sourceIntFromTo #-}
52sourceIntFromTo :: MonadIO m => Int -> m (Stream Int)
53sourceIntFromTo n = S.fold (A.writeN value) $ S.enumerateFromTo n (n + value)
55{-# INLINE sourceIntFromToFromList #-}
56sourceIntFromToFromList :: MonadIO m => Int -> m (Stream Int)
57sourceIntFromToFromList n = P.return $ (A.fromListN value) $ [n..n + value]
59{-# INLINE sourceFromList #-}
60sourceFromList :: MonadIO m => Int -> m (Stream Int)
61sourceFromList n = S.fold (A.writeN value) $ S.fromList [n..n+value]
63-------------------------------------------------------------------------------
65-------------------------------------------------------------------------------
67{-# INLINE composeN #-}
69 => Int -> (Stream Int -> m (Stream Int)) -> Stream Int -> m (Stream Int)
74 3 -> f x P.>>= f P.>>= f
75 4 -> f x P.>>= f P.>>= f P.>>= f
83 :: MonadIO m => Int -> Stream Int -> m (Stream Int)
87 :: MonadIO m => (S.SerialT m Int -> S.SerialT m Int)
90onArray f arr = S.fold (A.writeN value) $ f $ (S.unfold A.read arr)
92scanl' n = composeN n $ onArray $ S.scanl' (+) 0
93scanl1' n = composeN n $ onArray $ S.scanl1' (+)
94map n = composeN n $ onArray $ S.map (+1)
96{-# INLINE eqInstance #-}
97eqInstance :: Stream Int -> Bool
98eqInstance src = src == src
100{-# INLINE eqInstanceNotEq #-}
101eqInstanceNotEq :: Stream Int -> Bool
102eqInstanceNotEq src = src P./= src
104{-# INLINE ordInstance #-}
105ordInstance :: Stream Int -> Bool
106ordInstance src = src P.< src
108{-# INLINE ordInstanceMin #-}
109ordInstanceMin :: Stream Int -> Stream Int
110ordInstanceMin src = P.min src src
112{-# INLINE showInstance #-}
113showInstance :: Stream Int -> P.String
114showInstance src = P.show src
116{-# INLINE readInstance #-}
117readInstance :: P.String -> Stream Int
122 _ -> P.error "readInstance: no parse"
124{-# INLINE pureFoldl' #-}
125pureFoldl' :: MonadIO m => Stream Int -> m Int
126pureFoldl' = S.foldl' (+) 0 . S.unfold A.read
129{-# INLINE foldableFoldl' #-}
130foldableFoldl' :: Stream Int -> Int
131foldableFoldl' = F.foldl' (+) 0
133{-# INLINE foldableSum #-}
134foldableSum :: Stream Int -> Int
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