on master help sign in
Add append benchmark to linear benchmarks
commitcf1388b330f30539018666fb9c6af96408e775bf authorHarendra Kumar <harendra.kumar@gmail.com> dateSun 6 May 2018, 05:13 (8 years ago) parentbe37a7a
3 files changed+22−2
bench.sh+1−1 benchmark/Linear.hs+10 benchmark/LinearOps.hs+11−1
bench.sh+1−1
@@ -4,7 +4,7 @@ print_help () {
44 echo "Usage: $0 "
55 echo " [--quick] [--append] "
66 echo " [--no-graphs] [--no-measure]"
7− echo " [--benchmark]"
7+ echo " [--benchmark <linear|nested>]"
88 echo " [--compare] [--base commit] [--candidate commit]"
99 echo " -- <gauge options>"
1010 echo
benchmark/Linear.hs+10
@@ -10,6 +10,7 @@ import Data.Functor.Identity (Identity, runIdentity)
1010import System.Random (randomRIO)
1111import qualified LinearOps as Ops
1212
13+import Streamly
1314import Gauge
1415
1516-- We need a monadic bind here to make sure that the function f does not get
@@ -17,6 +18,9 @@ import Gauge
1718benchIO :: (NFData b) => String -> (Ops.Stream m Int -> IO b) -> Benchmark
1819benchIO name f = bench name $ nfIO $ randomRIO (1,1000) >>= f . Ops.source
1920
21+benchIOAppend :: (NFData b) => String -> (Int -> IO b) -> Benchmark
22+benchIOAppend name f = bench name $ nfIO $ randomRIO (1,1000) >>= f
23+
2024_benchId :: (NFData b) => String -> (Ops.Stream m Int -> Identity b) -> Benchmark
2125_benchId name f = bench name $ nf (runIdentity . f) (Ops.source 10)
2226
@@ -45,6 +49,12 @@ main = do
4549 , benchIO "dropWhile-true" Ops.dropWhileTrue
4650 ]
4751 , 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+ ]
4858 , bgroup "compose"
4959 [ benchIO "mapM" Ops.composeMapM
5060 , benchIO "map-with-all-in-filter" Ops.composeMapAllInFilter
benchmark/LinearOps.hs+11−1
@@ -9,7 +9,7 @@ module LinearOps where
99
1010import Prelude
1111 (Monad, Int, (+), ($), (.), return, fmap, even, (>), (<=),
12− subtract, undefined, Maybe)
12+ subtract, undefined, Maybe, Monoid, foldMap)
1313
1414import qualified Streamly as S
1515import qualified Streamly.Prelude as S
@@ -103,6 +103,16 @@ dropWhileTrue = transform . S.dropWhile (<= maxValue)
103103zip src = transform $ (S.zipWith (,) src src)
104104concat _n = return ()
105105
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+
106116-------------------------------------------------------------------------------
107117-- Composition
108118-------------------------------------------------------------------------------