@@ -15,11 +15,16 @@ import Gauge
16-- 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-- completely optimized out by the compiler in some cases.
17-- completely optimized out by the compiler in some cases.
18−benchIO :: NFData b => String -> (Ops.Stream m Int -> IO b) -> Benchmark
18+benchIO :: (IsStream t, NFData b) => String -> (t IO Int -> IO b) -> Benchmark
19benchIO name f = bench name $ nfIO $ randomRIO (1,1000) >>= f . Ops.source
19benchIO name f = bench name $ nfIO $ randomRIO (1,1000) >>= f . Ops.source
21−benchSrcIO :: String -> (Int -> Ops.Stream IO Int) -> Benchmark
21+benchSrcIO
22+ :: (t IO Int -> SerialT IO Int)
22−benchSrcIO name f = bench name $ nfIO $ randomRIO (1,1000) >>= Ops.toNull . f
27+ = bench name $ nfIO $ randomRIO (1,1000) >>= Ops.toNull t . f
24benchIOAppend :: (NFData b) => String -> (Int -> IO b) -> Benchmark
29benchIOAppend :: (NFData b) => String -> (Int -> IO b) -> Benchmark
25benchIOAppend name f = bench name $ nfIO $ randomRIO (1,1000) >>= f
30benchIOAppend name f = bench name $ nfIO $ randomRIO (1,1000) >>= f
@@ -30,12 +35,57 @@ _benchId name f = bench name $ nf (runIdentity . f) (Ops.source 10)
30main :: IO ()
35main :: IO ()
32 defaultMain
37 defaultMain
38+ [ bgroup "generation"
40+ [ benchIO "unfoldr" $ Ops.toNull serially
41+ , benchSrcIO serially "fromFoldable" Ops.sourceFromFoldable
42+ , benchSrcIO serially "foldMapWith" Ops.sourceFoldMapWith
43+ , benchSrcIO serially "unfoldrM" Ops.sourceUnfoldrM
44+ , benchSrcIO serially "fromFoldableM" Ops.sourceFromFoldableM
45+ , benchSrcIO serially "foldMapWithM" Ops.sourceFoldMapWithM
47+ -- unfoldr and fromFoldable are always serial and thereofore the same for
50+ [ -- benchIO "unfoldr" $ Ops.toNull aheadly
51+ -- , benchSrcIO aheadly "fromFoldable" Ops.sourceFromFoldable
52+ benchSrcIO aheadly "foldMapWith" Ops.sourceFoldMapWith
53+ , benchSrcIO aheadly "unfoldrM" Ops.sourceUnfoldrM
54+ , benchSrcIO aheadly "fromFoldableM" Ops.sourceFromFoldableM
55+ , benchSrcIO aheadly "foldMapWithM" Ops.sourceFoldMapWithM
58+ [ -- benchIO "unfoldr" $ Ops.toNull asyncly
59+ -- , benchSrcIO asyncly "fromFoldable" Ops.sourceFromFoldable
60+ benchSrcIO asyncly "foldMapWith" Ops.sourceFoldMapWith
61+ , benchSrcIO asyncly "unfoldrM" Ops.sourceUnfoldrM
62+ , benchSrcIO asyncly "fromFoldableM" Ops.sourceFromFoldableM
63+ , benchSrcIO asyncly "foldMapWithM" Ops.sourceFoldMapWithM
65+ -- XXX need to use smaller streams to finish in reasonable time
67+ [ --benchIO "unfoldr" $ Ops.toNull parallely
68+ --, benchSrcIO parallely "fromFoldable" Ops.sourceFromFoldable
69+ --, benchSrcIO parallely "foldMapWith" Ops.sourceFoldMapWith
70+ -- , benchSrcIO parallely "unfoldrM" Ops.sourceUnfoldrM
71+ -- , benchSrcIO parallely "fromFoldableM" Ops.sourceFromFoldableM
72+ -- , benchSrcIO parallely "foldMapWithM" Ops.sourceFoldMapWithM
75+ -- XXX this is the same foldMapWith in the above benchmarks, need to dedup
76+ -- this one provides a single place comparsion of all types and uses
77+ -- smaller stream size for faster benchmarking. We can use the same for
78+ -- above benchmarks and remove this.
80+ [ benchIOAppend "serially" $ Ops.append serially
81+ , benchIOAppend "wSerially" $ Ops.append wSerially
82+ , benchIOAppend "aheadly" $ Ops.append aheadly
83+ , benchIOAppend "asyncly" $ Ops.append asyncly
84+ , benchIOAppend "wAsyncly" $ Ops.append wAsyncly
85+ , benchIOAppend "parallely" $ Ops.append parallely
33− [ bgroup "elimination"
87+ , bgroup "elimination"
34− [ benchIO "toNull" Ops.toNull
88+ [ benchIO "toNull" $ Ops.toNull serially
35− , benchSrcIO "fromFoldable" Ops.sourceFromFoldable
36− , benchSrcIO "fromFoldableM" Ops.sourceFromFoldableM
37− , benchSrcIO "foldMapWith" Ops.sourceFoldMapWith
38− , benchSrcIO "unfoldrM" Ops.sourceUnfoldrM
39 , benchIO "toList" Ops.toList
89 , benchIO "toList" Ops.toList
40 , benchIO "fold" Ops.foldl
90 , benchIO "fold" Ops.foldl
41 , benchIO "last" Ops.last
91 , benchIO "last" Ops.last
@@ -56,14 +106,6 @@ main = do
56 , benchIO "dropWhile-true" Ops.dropWhileTrue
106 , benchIO "dropWhile-true" Ops.dropWhileTrue
58 , benchIO "zip" Ops.zip
108 , benchIO "zip" Ops.zip
60− [ benchIOAppend "serially" $ Ops.append serially
61− , benchIOAppend "wSerially" $ Ops.append wSerially
62− , benchIOAppend "aheadly" $ Ops.append aheadly
63− , benchIOAppend "asyncly" $ Ops.append asyncly
64− , benchIOAppend "wAsyncly" $ Ops.append wAsyncly
65− , benchIOAppend "parallely" $ Ops.append parallely
67 , bgroup "compose"
109 , bgroup "compose"
68 [ benchIO "mapM" Ops.composeMapM
110 [ benchIO "mapM" Ops.composeMapM
69 , benchIO "map-with-all-in-filter" Ops.composeMapAllInFilter
111 , benchIO "map-with-all-in-filter" Ops.composeMapAllInFilter