on master help sign in
Add more benchmarks to unpinned-array.
42f1091Pranay Sashank
benchmark/Streamly/Benchmark/Data/Array.hs+10−7
@@ -11,7 +11,7 @@
11
11
12module Main (main) where
12module Main (main) where
13
13
14−import Control.DeepSeq (NFData(..))
14+import Control.DeepSeq (NFData(..), deepseq)
15import System.Random (randomRIO)
15import System.Random (randomRIO)
16
16
17import qualified Streamly.Benchmark.Data.ArrayOps as Ops
17import qualified Streamly.Benchmark.Data.ArrayOps as Ops
@@ -48,6 +48,9 @@ benchIO' name src f = bench name $ nfIO $
48benchIOSink :: NFData b => String -> (Ops.Stream Int -> IO b) -> Benchmark
48benchIOSink :: NFData b => String -> (Ops.Stream Int -> IO b) -> Benchmark
49benchIOSink name f = benchIO' name Ops.sourceIntFromTo f
49benchIOSink name f = benchIO' name Ops.sourceIntFromTo f
50
50
51+mkString :: String
52+mkString = "[1" ++ concat (replicate Ops.value ",1") ++ "]"
53+
51main :: IO ()
54main :: IO ()
52main =
55main =
53 defaultMain
56 defaultMain
@@ -60,15 +63,15 @@ main =
60 , benchIOSrc "writeN . fromList" Ops.sourceFromList
63 , benchIOSrc "writeN . fromList" Ops.sourceFromList
61 -- , benchPureSrc "writeN . IsList.fromList" Ops.sourceIsList
64 -- , benchPureSrc "writeN . IsList.fromList" Ops.sourceIsList
62 -- , benchPureSrc "writeN . IsString.fromString" Ops.sourceIsString
65 -- , benchPureSrc "writeN . IsString.fromString" Ops.sourceIsString
63− -- , mkString `deepseq` (bench "read" $ nf Ops.readInstance mkString)
66+ , mkString `deepseq` (bench "read" $ nf Ops.readInstance mkString)
64− -- , benchPureSink "show" Ops.showInstance
67+ , benchPureSink "show" Ops.showInstance
65 ]
68 ]
66 , bgroup "elimination"
69 , bgroup "elimination"
67 [ benchPureSink "id" id
70 [ benchPureSink "id" id
68− -- , benchPureSink "==" Ops.eqInstance
71+ , benchPureSink "==" Ops.eqInstance
69− -- , benchPureSink "/=" Ops.eqInstanceNotEq
72+ , benchPureSink "/=" Ops.eqInstanceNotEq
70− -- , benchPureSink "<" Ops.ordInstance
73+ , benchPureSink "<" Ops.ordInstance
71− -- , benchPureSink "min" Ops.ordInstanceMin
74+ , benchPureSink "min" Ops.ordInstanceMin
72 -- length is used to check for foldr/build fusion
75 -- length is used to check for foldr/build fusion
73 -- , benchPureSink "length . IsList.toList" (length . GHC.toList)
76 -- , benchPureSink "length . IsList.toList" (length . GHC.toList)
74 , benchIOSink "foldl'" Ops.pureFoldl'
77 , benchIOSink "foldl'" Ops.pureFoldl'
benchmark/Streamly/Benchmark/Data/ArrayOps.hs+4−4
@@ -16,7 +16,7 @@
16module Streamly.Benchmark.Data.ArrayOps where
16module Streamly.Benchmark.Data.ArrayOps where
17
17
18import Control.Monad.IO.Class (MonadIO)
18import Control.Monad.IO.Class (MonadIO)
19−import Prelude (Int, (+), ($), (>), (.), Maybe(..), undefined)
19+import Prelude (Int, Bool, (+), ($), (==), (>), (.), Maybe(..), undefined)
20import qualified Prelude as P
20import qualified Prelude as P
21#ifdef DEVBUILD
21#ifdef DEVBUILD
22import qualified Data.Foldable as F
22import qualified Data.Foldable as F
@@ -27,7 +27,7 @@ import qualified Streamly.Data.Array as A
27import qualified Streamly.Prelude as S
27import qualified Streamly.Prelude as S
28
28
29value :: Int
29value :: Int
30−value = 10000
30+value = 100000
31
31
32-------------------------------------------------------------------------------
32-------------------------------------------------------------------------------
33-- Benchmark ops
33-- Benchmark ops
@@ -104,7 +104,7 @@ onArray f arr = S.fold (A.writeN value) $ f $ (S.unfold A.read arr)
104scanl' n = composeN n $ onArray $ S.scanl' (+) 0
104scanl' n = composeN n $ onArray $ S.scanl' (+) 0
105scanl1' n = composeN n $ onArray $ S.scanl1' (+)
105scanl1' n = composeN n $ onArray $ S.scanl1' (+)
106map n = composeN n $ onArray $ S.map (+1)
106map n = composeN n $ onArray $ S.map (+1)
107−{-
107+
108{-# INLINE eqInstance #-}
108{-# INLINE eqInstance #-}
109eqInstance :: Stream Int -> Bool
109eqInstance :: Stream Int -> Bool
110eqInstance src = src == src
110eqInstance src = src == src
@@ -132,7 +132,7 @@ readInstance str =
132 in case r of
132 in case r of
133 [(x,"")] -> x
133 [(x,"")] -> x
134 _ -> P.error "readInstance: no parse"
134 _ -> P.error "readInstance: no parse"
135−-}
135+
136{-# INLINE pureFoldl' #-}
136{-# INLINE pureFoldl' #-}
137pureFoldl' :: MonadIO m => Stream Int -> m Int
137pureFoldl' :: MonadIO m => Stream Int -> m Int
138pureFoldl' = S.foldl' (+) 0 . S.unfold A.read
138pureFoldl' = S.foldl' (+) 0 . S.unfold A.read