on master help sign in
Add benchmarks for Alternative parser
a0cbb73Harendra Kumar
benchmark/Streamly/Benchmark/Data/Parser.hs+23
@@ -306,6 +306,27 @@ split_ value =
306 (PR.dropWhile (<= value))
306 (PR.dropWhile (<= value))
307 )
307 )
308
308
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+
309{-# INLINE takeEndBy_ #-}
330{-# INLINE takeEndBy_ #-}
310takeEndBy_ :: Monad m
331takeEndBy_ :: Monad m
311 => Int -> Stream m Int -> m (Either ParseError ())
332 => Int -> Stream m Int -> m (Either ParseError ())
@@ -513,6 +534,8 @@ o_n_heap_serial value =
513
534
514 -- non-linear time complexity (parserD)
535 -- non-linear time complexity (parserD)
515 , benchIOSink value "split_" $ split_ value
536 , benchIOSink value "split_" $ split_ value
537+ , benchIOSink value "altSmall (2 x parseMany)" $ altSmall value
538+ , benchIOSink value "altBig (1/2 x 2)" $ alt value
516 -- XXX why O(n) heap?
539 -- XXX why O(n) heap?
517 -- , benchIOSink value "choice" $ choice value
540 -- , benchIOSink value "choice" $ choice value
518
541