on master help sign in
Add append benchmark to linear benchmarks
cf1388bHarendra Kumar
bench.sh+1−1
@@ -4,7 +4,7 @@ print_help () {
4 echo "Usage: $0 "
4 echo "Usage: $0 "
5 echo " [--quick] [--append] "
5 echo " [--quick] [--append] "
6 echo " [--no-graphs] [--no-measure]"
6 echo " [--no-graphs] [--no-measure]"
7− echo " [--benchmark]"
7+ echo " [--benchmark <linear|nested>]"
8 echo " [--compare] [--base commit] [--candidate commit]"
8 echo " [--compare] [--base commit] [--candidate commit]"
9 echo " -- <gauge options>"
9 echo " -- <gauge options>"
10 echo
10 echo
benchmark/Linear.hs+10
@@ -10,6 +10,7 @@ import Data.Functor.Identity (Identity, runIdentity)
10import System.Random (randomRIO)
10import System.Random (randomRIO)
11import qualified LinearOps as Ops
11import qualified LinearOps as Ops
12
12
13+import Streamly
13import Gauge
14import Gauge
14
15
15-- We need a monadic bind here to make sure that the function f does not get
16-- We need a monadic bind here to make sure that the function f does not get
@@ -17,6 +18,9 @@ import Gauge
17benchIO :: (NFData b) => String -> (Ops.Stream m Int -> IO b) -> Benchmark
18benchIO :: (NFData b) => String -> (Ops.Stream m Int -> IO b) -> Benchmark
18benchIO name f = bench name $ nfIO $ randomRIO (1,1000) >>= f . Ops.source
19benchIO name f = bench name $ nfIO $ randomRIO (1,1000) >>= f . Ops.source
19
20
21+benchIOAppend :: (NFData b) => String -> (Int -> IO b) -> Benchmark
22+benchIOAppend name f = bench name $ nfIO $ randomRIO (1,1000) >>= f
23+
20_benchId :: (NFData b) => String -> (Ops.Stream m Int -> Identity b) -> Benchmark
24_benchId :: (NFData b) => String -> (Ops.Stream m Int -> Identity b) -> Benchmark
21_benchId name f = bench name $ nf (runIdentity . f) (Ops.source 10)
25_benchId name f = bench name $ nf (runIdentity . f) (Ops.source 10)
22
26
@@ -45,6 +49,12 @@ main = do
45 , benchIO "dropWhile-true" Ops.dropWhileTrue
49 , benchIO "dropWhile-true" Ops.dropWhileTrue
46 ]
50 ]
47 , benchIO "zip" Ops.zip
51 , benchIO "zip" Ops.zip
52+ , bgroup "append"
53+ [ benchIOAppend "streamly" $ Ops.append streamly
54+ , benchIOAppend "costreamly" $ Ops.append costreamly
55+ , benchIOAppend "coparallely" $ Ops.append coparallely
56+ , benchIOAppend "parallely" $ Ops.append parallely
57+ ]
48 , bgroup "compose"
58 , bgroup "compose"
49 [ benchIO "mapM" Ops.composeMapM
59 [ benchIO "mapM" Ops.composeMapM
50 , benchIO "map-with-all-in-filter" Ops.composeMapAllInFilter
60 , benchIO "map-with-all-in-filter" Ops.composeMapAllInFilter
benchmark/LinearOps.hs+11−1
@@ -9,7 +9,7 @@ module LinearOps where
9
9
10import Prelude
10import Prelude
11 (Monad, Int, (+), ($), (.), return, fmap, even, (>), (<=),
11 (Monad, Int, (+), ($), (.), return, fmap, even, (>), (<=),
12− subtract, undefined, Maybe)
12+ subtract, undefined, Maybe, Monoid, foldMap)
13
13
14import qualified Streamly as S
14import qualified Streamly as S
15import qualified Streamly.Prelude as S
15import qualified Streamly.Prelude as S
@@ -103,6 +103,16 @@ dropWhileTrue = transform . S.dropWhile (<= maxValue)
103zip src = transform $ (S.zipWith (,) src src)
103zip src = transform $ (S.zipWith (,) src src)
104concat _n = return ()
104concat _n = return ()
105
105
106+-------------------------------------------------------------------------------
107+-- Append
108+-------------------------------------------------------------------------------
109+
110+{-# INLINE append #-}
111+append
112+ :: (Monoid (t m Int), Monad m, Monad (t m))
113+ => (t m Int -> S.StreamT m Int) -> Int -> m ()
114+append t n = runStream $ t $ foldMap return [n..n+value]
115+
106-------------------------------------------------------------------------------
116-------------------------------------------------------------------------------
107-- Composition
117-- Composition
108-------------------------------------------------------------------------------
118-------------------------------------------------------------------------------