on master help sign in
Add benchmarks for Alternative parser
commita0cbb73877c0627da55a8407e88add554a39058d authorHarendra Kumar <harendra@composewell.com> dateMon 27 Feb 2023, 18:09 (4 years ago) parentafea22c
1 file changed+23
benchmark/Streamly/Benchmark/Data/Parser.hs+23
benchmark/Streamly/Benchmark/Data/Parser.hs+23
@@ -306,6 +306,27 @@ split_ value =
306306 (PR.dropWhile (<= value))
307307 )
308308
309+{-# INLINE alt #-}
310+alt :: Monad m
311+ => Int -> Stream m Int -> m (Either ParseError ())
312+alt value =
313+ Stream.parse
314+ (PR.alt
315+ (PR.dropWhile (<= (value `div` 2)) *> PR.die "alt")
316+ (PR.dropWhile (<= value))
317+ )
318+
319+{-# INLINE altSmall #-}
320+altSmall :: Monad m
321+ => Int -> Stream m Int -> m ()
322+altSmall value =
323+ Stream.fold Fold.drain .
324+ Stream.parseMany
325+ (PR.alt
326+ (PR.satisfy (>= value) *> PR.die "alt")
327+ (PR.satisfy (<= value))
328+ )
329+
309330{-# INLINE takeEndBy_ #-}
310331takeEndBy_ :: Monad m
311332 => Int -> Stream m Int -> m (Either ParseError ())
@@ -513,6 +534,8 @@ o_n_heap_serial value =
513534
514535 -- non-linear time complexity (parserD)
515536 , benchIOSink value "split_" $ split_ value
537+ , benchIOSink value "altSmall (2 x parseMany)" $ altSmall value
538+ , benchIOSink value "altBig (1/2 x 2)" $ alt value
516539 -- XXX why O(n) heap?
517540 -- , benchIOSink value "choice" $ choice value
518541