3-- Copyright : (c) 2019 Composewell Technologies
5-- License : BSD-3-Clause
6-- Maintainer : streamly@composewell.com
7-- Stability : experimental
12module Main (main) where
14import Control.DeepSeq (NFData(..))
15import System.Random (randomRIO)
17import qualified Streamly.Benchmark.Data.Prim.ArrayOps as Ops
18import qualified Streamly.Internal.Data.Prim.Array as A
19import qualified Streamly.Prelude as S
21import Streamly.Benchmark.Common
24-------------------------------------------------------------------------------
26-------------------------------------------------------------------------------
29benchIO :: NFData b => String -> (Int -> IO a) -> (a -> b) -> Benchmark
30benchIO name src f = bench name $ nfIO $
31 randomRIO (1,1) >>= src >>= return . f
33-- Drain a source that generates an array in the IO monad
34{-# INLINE benchIOSrc #-}
35benchIOSrc :: A.Prim a => String -> (Int -> IO (Ops.Stream a)) -> Benchmark
36benchIOSrc name src = benchIO name src id
38{-# INLINE benchPureSink #-}
39benchPureSink :: NFData b => String -> (Ops.Stream Int -> b) -> Benchmark
40benchPureSink name f = benchIO name Ops.sourceIntFromTo f
42{-# INLINE benchIO' #-}
43benchIO' :: NFData b => String -> (Int -> IO a) -> (a -> IO b) -> Benchmark
44benchIO' name src f = bench name $ nfIO $
45 randomRIO (1,1) >>= src >>= f
47{-# INLINE benchIOSink #-}
48benchIOSink :: NFData b => String -> (Ops.Stream Int -> IO b) -> Benchmark
49benchIOSink name f = benchIO' name Ops.sourceIntFromTo f
53testStr = mkListString Ops.value
57moduleName = "Data.Prim.Array"
59o_1_space :: [Benchmark]
61 [ bgroup (o_1_space_prefix moduleName)
63 [ benchIOSrc "writeN . intFromTo" Ops.sourceIntFromTo
64 , benchIOSrc "write . intFromTo" Ops.sourceIntFromToFromStream
65 , benchIOSrc "fromList . intFromTo" Ops.sourceIntFromToFromList
66 , benchIOSrc "writeN . unfoldr" Ops.sourceUnfoldr
67 , benchIOSrc "writeN . fromList" Ops.sourceFromList
68 -- , benchPureSrc "writeN . IsList.fromList" Ops.sourceIsList
69 -- , benchPureSrc "writeN . IsString.fromString" Ops.sourceIsString
70 -- , testStr `deepseq` (bench "read" $ nf Ops.readInstance testStr)
71 , benchPureSink "show" Ops.showInstance
73 , bgroup "elimination"
74 [ benchPureSink "id" id
75 , benchPureSink "==" Ops.eqInstance
76 , benchPureSink "/=" Ops.eqInstanceNotEq
77 , benchPureSink "<" Ops.ordInstance
78 , benchPureSink "min" Ops.ordInstanceMin
79 -- length is used to check for foldr/build fusion
80 -- , benchPureSink "length . IsList.toList" (length . GHC.toList)
81 , benchIOSink "foldl'" Ops.pureFoldl'
82 , benchIOSink "read" (S.drain . S.unfold A.read)
83 , benchIOSink "toStreamRev" (S.drain . A.toStreamRev)
85 -- PrimArray does not have a Foldable instance because it requires a
86 -- Prim constraint. Though it should be possible to make an instance in
87 -- the same way as we do in Memory.Array.
88 , benchPureSink "foldable/foldl'" Ops.foldableFoldl'
89 , benchPureSink "foldable/sum" Ops.foldableSum
92 , bgroup "transformation"
93 [ benchIOSink "scanl'" (Ops.scanl' 1)
94 , benchIOSink "scanl1'" (Ops.scanl1' 1)
95 , benchIOSink "map" (Ops.map 1)
97 , bgroup "transformationX4"
98 [ benchIOSink "scanl'" (Ops.scanl' 4)
99 , benchIOSink "scanl1'" (Ops.scanl1' 4)
100 , benchIOSink "map" (Ops.map 4)
106main = defaultMain $ concat [o_1_space]
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