on master help sign in
Fix the perf of parseGroupRollingEither benchmarks
41e878bHarendra Kumar
benchmark/Streamly/Benchmark/Data/Parser/ParserD.hs+17−14
@@ -62,17 +62,6 @@ benchIOSink
62benchIOSink value name f =
62benchIOSink value name f =
63 bench name $ nfIO $ randomRIO (1,1) >>= f . sourceUnfoldrM value
63 bench name $ nfIO $ randomRIO (1,1) >>= f . sourceUnfoldrM value
64
64
65−-- Make the input unsorted.
66−{-# INLINE benchIOSinkRandom #-}
67−benchIOSinkRandom
68− :: (NFData b)
69− => Int -> String -> (Stream IO Int -> IO b) -> Benchmark
70−benchIOSinkRandom value name f =
71− bench name $ nfIO $ randomRIO (1,1)
72− >>= f
73− . fmap (\x -> if even x then x + 2 else x)
74− . sourceUnfoldrM value
75−
76-------------------------------------------------------------------------------
65-------------------------------------------------------------------------------
77-- Parsers
66-- Parsers
78-------------------------------------------------------------------------------
67-------------------------------------------------------------------------------
@@ -252,6 +241,7 @@ parseManyGroupsRollingEitherAlt :: (MonadThrow m, MonadCatch m) =>
252 (Int -> Int -> Bool) -> Int -> m ()
241 (Int -> Int -> Bool) -> Int -> m ()
253parseManyGroupsRollingEitherAlt cmp value = do
242parseManyGroupsRollingEitherAlt cmp value = do
254 sourceUnfoldrM value 1
243 sourceUnfoldrM value 1
244+ -- Make the input unsorted.
255 & fmap (\x -> if even x then x + 2 else x)
245 & fmap (\x -> if even x then x + 2 else x)
256 & Stream.parseManyD (PR.groupByRollingEither cmp Fold.drain Fold.drain)
246 & Stream.parseManyD (PR.groupByRollingEither cmp Fold.drain Fold.drain)
257 & Stream.fold Fold.drain
247 & Stream.fold Fold.drain
@@ -285,6 +275,7 @@ lookAhead :: MonadThrow m => Int -> Stream m Int -> m ()
285lookAhead value =
275lookAhead value =
286 Stream.parseD (PR.lookAhead (PR.takeWhile (<= value) Fold.drain) $> ())
276 Stream.parseD (PR.lookAhead (PR.takeWhile (<= value) Fold.drain) $> ())
287
277
278+-- XXX The timing of this increased 3x after the stepify extract changes.
288{-# INLINE sequenceA_ #-}
279{-# INLINE sequenceA_ #-}
289sequenceA_ :: MonadThrow m => Int -> Stream m Int -> m ()
280sequenceA_ :: MonadThrow m => Int -> Stream m Int -> m ()
290sequenceA_ value =
281sequenceA_ value =
@@ -380,13 +371,25 @@ o_1_space_serial_nested value =
380 , benchIOSink value "parseMany groupRollingBy (1 group)"
371 , benchIOSink value "parseMany groupRollingBy (1 group)"
381 $ parseManyGroupsRolling True
372 $ parseManyGroupsRolling True
382 , bench "parseMany groupRollingByEither (Left)"
373 , bench "parseMany groupRollingByEither (Left)"
383− $ nfIO $ parseManyGroupsRollingEither (<) value
374+ $ nfIO $ parseManyGroupsRollingEitherLeft
384 , bench "parseMany groupRollingByEither (Right)"
375 , bench "parseMany groupRollingByEither (Right)"
385− $ nfIO $ parseManyGroupsRollingEither (>) value
376+ $ nfIO $ parseManyGroupsRollingEitherRight
386 , bench "parseMany groupRollingByEither (Alternating)"
377 , bench "parseMany groupRollingByEither (Alternating)"
387− $ nfIO $ parseManyGroupsRollingEitherAlt (>) value
378+ $ nfIO $ parseManyGroupsRollingEitherAlt1
388 ]
379 ]
389
380
381+ where
382+
383+ {-# NOINLINE parseManyGroupsRollingEitherLeft #-}
384+ parseManyGroupsRollingEitherLeft = parseManyGroupsRollingEither (<) value
385+
386+ {-# NOINLINE parseManyGroupsRollingEitherRight #-}
387+ parseManyGroupsRollingEitherRight = parseManyGroupsRollingEither (>) value
388+
389+ {-# NOINLINE parseManyGroupsRollingEitherAlt1 #-}
390+ parseManyGroupsRollingEitherAlt1 =
391+ parseManyGroupsRollingEitherAlt (>) value
392+
390o_1_space_serial_unfold :: Int -> [Array.Array Int] -> [Benchmark]
393o_1_space_serial_unfold :: Int -> [Array.Array Int] -> [Benchmark]
391o_1_space_serial_unfold bound arrays =
394o_1_space_serial_unfold bound arrays =
392 [ bench "parseMany/Unfold/1000 arrays/1 parse"
395 [ bench "parseMany/Unfold/1000 arrays/1 parse"