99{-# LANGUAGE FlexibleContexts #-}
1010{-# LANGUAGE ScopedTypeVariables #-}
1111
12- -- Benchmarks for operations exported from Streamly.Internal.Data.Scanl.Container.
12+ -- Benchmarks for operations exported from
13+ -- Streamly.Internal.Data.Scanl.Container.
1314module Scanl.Container (benchmarks ) where
1415
15- import GHC.Types (SPEC (.. ))
1616import Data.IORef (IORef , newIORef , readIORef , modifyIORef )
1717import Data.IntSet (IntSet )
1818import Data.Map.Strict (Map )
@@ -110,56 +110,67 @@ nubInt n = withPostscanl n Scanl.nubInt
110110-- Demultiplexing
111111-------------------------------------------------------------------------------
112112
113- {-# ANN demuxIOOneShot (PermitPatternMatches [''Map,''Set,''Maybe,''STRef,''Bool,''IO,''Int,''FL.Step,''Step,''Scanl,''Tuple'Fused,''Tuple']) #-}
114- {-# ANN demuxIOOneShot (PermitConstructions [''Int,''Map,''Maybe,''Scanl,''Set,''SrcLoc,''CallStack,''Step,''FL.Step,''STRef,''Tuple',''Tuple'Fused,''(),''Bool]) #-}
115- {-# ANN demuxIOOneShot (PermitTypeClasses [''IP]) #-}
116- {-# NOINLINE demuxIOOneShot #-}
117- demuxIOOneShot :: Int -> Int -> IO ()
118- demuxIOOneShot len =
113+ {-# ANN demuxIO_Sum100 (PermitPatternMatches
114+ [''Map,''Set,''Maybe,''STRef,''Bool,''IO,''Int,''FL.Step,''Step
115+ ,''Scanl,''Tuple'Fused,''Tuple']) #-}
116+ {-# ANN demuxIO_Sum100 (PermitConstructions
117+ [''Int,''Map,''Maybe,''Scanl,''Set,''SrcLoc,''CallStack,''Step
118+ ,''FL.Step,''STRef,''Tuple',''Tuple'Fused,''(),''Bool]) #-}
119+ {-# ANN demuxIO_Sum100 (PermitTypeClasses [''IP]) #-}
120+ {-# NOINLINE demuxIO_Sum100 #-}
121+ demuxIO_Sum100 :: Int -> Int -> IO ()
122+ demuxIO_Sum100 len =
119123 withStream len $
120124 Stream. fold FL. drain
121125 . Stream. postscanl (Scanl. demuxIO (getKey 64 ) getScanl)
122126
123- {-# ANN demuxIOSum (PermitPatternMatches [''Map,''STRef,''IO,''Int,''FL.Step,''Step,''Scanl,''Tuple']) #-}
124- {-# ANN demuxIOSum (PermitConstructions [''Int,''Map,''SrcLoc,''CallStack,''Step,''Tuple',''()]) #-}
125- {-# ANN demuxIOSum (PermitTypeClasses [''IP]) #-}
126- {-# NOINLINE demuxIOSum #-}
127- demuxIOSum :: Int -> Int -> IO ()
128- demuxIOSum len =
127+ {-# ANN demuxIO_Sum (PermitPatternMatches
128+ [''Map,''STRef,''IO,''Int,''FL.Step,''Step,''Scanl,''Tuple']) #-}
129+ {-# ANN demuxIO_Sum (PermitConstructions
130+ [''Int,''Map,''SrcLoc,''CallStack,''Step,''Tuple',''()]) #-}
131+ {-# ANN demuxIO_Sum (PermitTypeClasses [''IP]) #-}
132+ {-# NOINLINE demuxIO_Sum #-}
133+ demuxIO_Sum :: Int -> Int -> IO ()
134+ demuxIO_Sum len =
129135 withStream len $
130136 Stream. fold FL. drain
131137 . Stream. postscanl
132138 (Scanl. demuxIO (getKey 64 ) (const (pure (Just Scanl. sum ))))
133139
134- {-# ANN demuxSum (PermitPatternMatches [''Map,''Int,''FL.Step,''Step,''Scanl,''Tuple']) #-}
135- {-# ANN demuxSum (PermitConstructions [''Int,''Map,''Step,''Tuple',''()]) #-}
136- {-# ANN demuxSum (PermitTypeClasses []) #-}
137- {-# NOINLINE demuxSum #-}
138- demuxSum :: Int -> Int -> IO ()
139- demuxSum len =
140+ {-# ANN demux_Sum (PermitPatternMatches
141+ [''Map,''Int,''FL.Step,''Step,''Scanl,''Tuple']) #-}
142+ {-# ANN demux_Sum (PermitConstructions [''Int,''Map,''Step,''Tuple',''()]) #-}
143+ {-# ANN demux_Sum (PermitTypeClasses []) #-}
144+ {-# NOINLINE demux_Sum #-}
145+ demux_Sum :: Int -> Int -> IO ()
146+ demux_Sum len =
140147 withStream len $
141148 Stream. fold FL. drain
142149 . Stream. postscanl
143150 (Scanl. demux (getKey 64 ) (const (pure (Just Scanl. sum ))))
144151
145- {-# ANN demuxGenericSum (PermitPatternMatches [''Map,''Maybe,''Int,''FL.Step,''Step,''Scanl,''Tuple']) #-}
146- {-# ANN demuxGenericSum (PermitConstructions [''Int,''Map,''Maybe,''Step,''Tuple',''()]) #-}
147- {-# ANN demuxGenericSum (PermitTypeClasses []) #-}
148- {-# NOINLINE demuxGenericSum #-}
149- demuxGenericSum :: Int -> Int -> IO ()
150- demuxGenericSum len =
152+ {-# ANN demuxGeneric_Sum (PermitPatternMatches
153+ [''Map,''Maybe,''Int,''FL.Step,''Step,''Scanl,''Tuple']) #-}
154+ {-# ANN demuxGeneric_Sum (PermitConstructions
155+ [''Int,''Map,''Maybe,''Step,''Tuple',''()]) #-}
156+ {-# ANN demuxGeneric_Sum (PermitTypeClasses []) #-}
157+ {-# NOINLINE demuxGeneric_Sum #-}
158+ demuxGeneric_Sum :: Int -> Int -> IO ()
159+ demuxGeneric_Sum len =
151160 withStream len $
152161 Stream. fold FL. drain
153162 . Stream. postscanl
154163 (Scanl. demuxGeneric (getKey 64 ) (const (pure (Just Scanl. sum )))
155164 :: Scanl IO Int (IO (Map Int Int ), Maybe (Int , Int )))
156165
157- {-# ANN demuxGenericIOSum (PermitPatternMatches [''Map,''Maybe,''STRef,''IO,''Int,''FL.Step,''Step,''Scanl,''Tuple']) #-}
158- {-# ANN demuxGenericIOSum (PermitConstructions [''Int,''Map,''Maybe,''SrcLoc,''CallStack,''Step,''Tuple',''()]) #-}
159- {-# ANN demuxGenericIOSum (PermitTypeClasses [''IP]) #-}
160- {-# NOINLINE demuxGenericIOSum #-}
161- demuxGenericIOSum :: Int -> Int -> IO ()
162- demuxGenericIOSum len =
166+ {-# ANN demuxGenericIO_Sum (PermitPatternMatches
167+ [''Map,''Maybe,''STRef,''IO,''Int,''FL.Step,''Step,''Scanl,''Tuple']) #-}
168+ {-# ANN demuxGenericIO_Sum (PermitConstructions
169+ [''Int,''Map,''Maybe,''SrcLoc,''CallStack,''Step,''Tuple',''()]) #-}
170+ {-# ANN demuxGenericIO_Sum (PermitTypeClasses [''IP]) #-}
171+ {-# NOINLINE demuxGenericIO_Sum #-}
172+ demuxGenericIO_Sum :: Int -> Int -> IO ()
173+ demuxGenericIO_Sum len =
163174 withStream len $
164175 Stream. fold FL. drain
165176 . Stream. postscanl
@@ -170,54 +181,60 @@ demuxGenericIOSum len =
170181-- Classifying
171182-------------------------------------------------------------------------------
172183
173- {-# ANN classifyLimitedSum (PermitPatternMatches [''Map,''Set,''STRef,''Int,''Tuple'Fused,''Tuple']) #-}
174- {-# ANN classifyLimitedSum (PermitConstructions [''Int,''Map,''Set,''()]) #-}
175- {-# ANN classifyLimitedSum (PermitTypeClasses []) #-}
176- {-# NOINLINE classifyLimitedSum #-}
177- classifyLimitedSum :: Int -> Int -> IO ()
178- classifyLimitedSum len =
184+ {-# ANN classifyIO_Sum100 (PermitPatternMatches
185+ [''Map,''Set,''STRef,''Int,''Tuple'Fused,''Tuple']) #-}
186+ {-# ANN classifyIO_Sum100 (PermitConstructions [''Int,''Map,''Set,''()]) #-}
187+ {-# ANN classifyIO_Sum100 (PermitTypeClasses []) #-}
188+ {-# NOINLINE classifyIO_Sum100 #-}
189+ classifyIO_Sum100 :: Int -> Int -> IO ()
190+ classifyIO_Sum100 len =
179191 withStream len $
180192 Stream. fold FL. drain
181193 . Stream. postscanl (Scanl. classifyIO (getKey 64 ) (limitedSum 100 ))
182194
183- {-# ANN classifyIOSum (PermitPatternMatches [''Map,''Set,''STRef,''Int,''Tuple']) #-}
184- {-# ANN classifyIOSum (PermitConstructions [''Int,''Map,''Set,''()]) #-}
185- {-# ANN classifyIOSum (PermitTypeClasses []) #-}
186- {-# NOINLINE classifyIOSum #-}
187- classifyIOSum :: Int -> Int -> IO ()
188- classifyIOSum len =
195+ {-# ANN classifyIO_Sum (PermitPatternMatches
196+ [''Map,''Set,''STRef,''Int,''Tuple']) #-}
197+ {-# ANN classifyIO_Sum (PermitConstructions [''Int,''Map,''Set,''()]) #-}
198+ {-# ANN classifyIO_Sum (PermitTypeClasses []) #-}
199+ {-# NOINLINE classifyIO_Sum #-}
200+ classifyIO_Sum :: Int -> Int -> IO ()
201+ classifyIO_Sum len =
189202 withStream len $
190203 Stream. fold FL. drain
191204 . Stream. postscanl (Scanl. classifyIO (getKey 64 ) Scanl. sum )
192205
193- {-# ANN classifySum (PermitPatternMatches [''Map,''Set,''Int,''Tuple']) #-}
194- {-# ANN classifySum (PermitConstructions [''Int,''Map,''Set,''()]) #-}
195- {-# ANN classifySum (PermitTypeClasses []) #-}
196- {-# NOINLINE classifySum #-}
197- classifySum :: Int -> Int -> IO ()
198- classifySum len =
206+ {-# ANN classify_Sum (PermitPatternMatches [''Map,''Set,''Int,''Tuple']) #-}
207+ {-# ANN classify_Sum (PermitConstructions [''Int,''Map,''Set,''()]) #-}
208+ {-# ANN classify_Sum (PermitTypeClasses []) #-}
209+ {-# NOINLINE classify_Sum #-}
210+ classify_Sum :: Int -> Int -> IO ()
211+ classify_Sum len =
199212 withStream len $
200213 Stream. fold FL. drain
201214 . Stream. postscanl (Scanl. classify (getKey 64 ) Scanl. sum )
202215
203- {-# ANN classifyGenericSum (PermitPatternMatches [''Map,''Set,''Maybe,''Int,''Tuple',''Tuple3']) #-}
204- {-# ANN classifyGenericSum (PermitConstructions [''Int,''Map,''Maybe,''Set,''Tuple3',''(,),''()]) #-}
205- {-# ANN classifyGenericSum (PermitTypeClasses []) #-}
206- {-# NOINLINE classifyGenericSum #-}
207- classifyGenericSum :: Int -> Int -> IO ()
208- classifyGenericSum len =
216+ {-# ANN classifyGeneric_Sum (PermitPatternMatches
217+ [''Map,''Set,''Maybe,''Int,''Tuple',''Tuple3']) #-}
218+ {-# ANN classifyGeneric_Sum (PermitConstructions
219+ [''Int,''Map,''Maybe,''Set,''Tuple3',''(,),''()]) #-}
220+ {-# ANN classifyGeneric_Sum (PermitTypeClasses []) #-}
221+ {-# NOINLINE classifyGeneric_Sum #-}
222+ classifyGeneric_Sum :: Int -> Int -> IO ()
223+ classifyGeneric_Sum len =
209224 withStream len $
210225 Stream. fold FL. drain
211226 . Stream. postscanl
212227 (Scanl. classifyGeneric (getKey 64 ) Scanl. sum
213228 :: Scanl IO Int (IO (Map Int Int ), Maybe (Int , Int )))
214229
215- {-# ANN classifyGenericIOSum (PermitPatternMatches [''Map,''Set,''Maybe,''STRef,''Int,''Tuple',''Tuple3']) #-}
216- {-# ANN classifyGenericIOSum (PermitConstructions [''Int,''Map,''Maybe,''Set,''Tuple3',''(,),''()]) #-}
217- {-# ANN classifyGenericIOSum (PermitTypeClasses []) #-}
218- {-# NOINLINE classifyGenericIOSum #-}
219- classifyGenericIOSum :: Int -> Int -> IO ()
220- classifyGenericIOSum len =
230+ {-# ANN classifyGenericIO_Sum (PermitPatternMatches
231+ [''Map,''Set,''Maybe,''STRef,''Int,''Tuple',''Tuple3']) #-}
232+ {-# ANN classifyGenericIO_Sum (PermitConstructions
233+ [''Int,''Map,''Maybe,''Set,''Tuple3',''(,),''()]) #-}
234+ {-# ANN classifyGenericIO_Sum (PermitTypeClasses []) #-}
235+ {-# NOINLINE classifyGenericIO_Sum #-}
236+ classifyGenericIO_Sum :: Int -> Int -> IO ()
237+ classifyGenericIO_Sum len =
221238 withStream len $
222239 Stream. fold FL. drain
223240 . Stream. postscanl
@@ -231,10 +248,10 @@ classifyGenericIOSum len =
231248benchmarks :: Int -> [(SpaceComplexity , Benchmark )]
232249benchmarks value =
233250 fmap (SpaceO_1 ,)
234- [ benchIO " demuxIO (1-shot) ( 64 buckets) [sum 100] " demuxIOOneShot value
235- , benchIO " demuxIO (64 buckets) [sum] " demuxIOSum value
236- , benchIO " classifyIO (64 buckets) [sum 100] " classifyLimitedSum value
237- , benchIO " classifyIO (64 buckets) [sum] " classifyIOSum value
251+ [ benchIO " demuxIO_Sum100 ( 64 buckets)" demuxIO_Sum100 value
252+ , benchIO " demuxIO_Sum (64 buckets)" demuxIO_Sum value
253+ , benchIO " classifyIO_Sum100 (64 buckets)" classifyIO_Sum100 value
254+ , benchIO " classifyIO_Sum (64 buckets)" classifyIO_Sum value
238255 ]
239256 ++ fmap (HeapO_n ,)
240257 [ benchIO " toSet" toSet value
@@ -243,10 +260,11 @@ benchmarks value =
243260 , benchIO " countDistinctInt" countDistinctInt value
244261 , benchIO " nub" nub value
245262 , benchIO " nubInt" nubInt value
246- , benchIO " demux (64 buckets) [sum]" demuxSum value
247- , benchIO " demuxGeneric (64 buckets) [sum]" demuxGenericSum value
248- , benchIO " demuxGenericIO (64 buckets) [sum]" demuxGenericIOSum value
249- , benchIO " classify (64 buckets) [sum]" classifySum value
250- , benchIO " classifyGeneric (64 buckets) [sum]" classifyGenericSum value
251- , benchIO " classifyGenericIO (64 buckets) [sum]" classifyGenericIOSum value
263+ , benchIO " demux_Sum (64 buckets)" demux_Sum value
264+ , benchIO " demuxGeneric_Sum (64 buckets)" demuxGeneric_Sum value
265+ , benchIO " demuxGenericIO_Sum (64 buckets)" demuxGenericIO_Sum value
266+ , benchIO " classify_Sum (64 buckets)" classify_Sum value
267+ , benchIO " classifyGeneric_Sum (64 buckets)" classifyGeneric_Sum value
268+ , benchIO " classifyGenericIO_Sum (64 buckets)" classifyGenericIO_Sum
269+ value
252270 ]
0 commit comments