55-- License : BSD-3-Clause
66-- Maintainer : streamly@composewell.com
77
8- -- BENCH_CHUNKED -> adaptC
9- -- BENCH_CHUNKED_GENERIC -> adaptCG
10- -- BENCH_SINGULAR -> adapt
8+ -- BENCH_CHUNKED -> parse from Array stream
9+ -- BENCH_CHUNKED_GENERIC -> parse from Generic Array stream
10+ -- BENCH_SINGULAR -> parse from single element stream
1111
1212{-# LANGUAGE CPP #-}
1313{-# LANGUAGE FlexibleContexts #-}
@@ -24,11 +24,9 @@ import Control.Monad.IO.Class (MonadIO)
2424import Data.Foldable (asum )
2525#ifdef BENCH_CHUNKED
2626import Streamly.Data.Array (Array , Unbox )
27- import qualified Streamly.Internal.Data.Array as Array (chunksOf )
2827#endif
2928#ifdef BENCH_CHUNKED_GENERIC
3029import Streamly.Data.Array.Generic (Array )
31- import qualified Streamly.Internal.Data.Array.Generic as GenArr (chunksOf )
3230#endif
3331import Streamly.Internal.Data.Fold (Fold (.. ))
3432import Streamly.Data.StreamK (StreamK )
@@ -48,6 +46,11 @@ import qualified Streamly.Internal.Data.Fold as Fold
4846import qualified Streamly.Data.Parser as PRD
4947import qualified Streamly.Internal.Data.ParserK as PR
5048import qualified Streamly.Internal.Data.StreamK as StreamK
49+ #ifdef BENCH_CHUNKED
50+ import qualified Streamly.Internal.Data.Array as Array
51+ #elif defined(BENCH_CHUNKED_GENERIC)
52+ import qualified Streamly.Internal.Data.Array.Generic as GenArr
53+ #endif
5154
5255import Test.Tasty.Bench
5356import Streamly.Benchmark.Common
@@ -58,8 +61,8 @@ import Streamly.Benchmark.Common
5861
5962#ifdef BENCH_CHUNKED
6063
61- #define PARSE_OP StreamK.parseChunks
62- #define FROM_PARSER adaptC
64+ #define PARSE_OP Array.parse
65+ #define FROM_PARSER Array.parserK
6366#define INPUT (Array a)
6467#define PARSE_ELEM (Array Int)
6568#define CONSTRAINT_IO (MonadIO m, Unbox a)
@@ -70,8 +73,8 @@ import Streamly.Benchmark.Common
7073
7174#ifdef BENCH_CHUNKED_GENERIC
7275
73- #define PARSE_OP StreamK.parseChunksGeneric
74- #define FROM_PARSER adaptCG
76+ #define PARSE_OP GenArr.parse
77+ #define FROM_PARSER GenArr.parserK
7578#define INPUT (Array a)
7679#define PARSE_ELEM (Array Int)
7780#define CONSTRAINT_IO (MonadIO m)
@@ -83,7 +86,7 @@ import Streamly.Benchmark.Common
8386#ifdef BENCH_SINGULAR
8487
8588#define PARSE_OP StreamK.parse
86- #define FROM_PARSER adapt
89+ #define FROM_PARSER PR.parserK
8790#define INPUT a
8891#define PARSE_ELEM Int
8992#define CONSTRAINT_IO (MonadIO m)
@@ -136,18 +139,18 @@ one value = PARSE_OP p
136139 where
137140
138141 p = do
139- m <- PR. FROM_PARSER (PRD. fromFold FL. one)
142+ m <- FROM_PARSER (PRD. fromFold FL. one)
140143 case m of
141144 Just i -> if i >= value then pure m else p
142145 Nothing -> pure Nothing
143146
144147{-# INLINE satisfy #-}
145148satisfy :: CONSTRAINT_IO => (a -> Bool ) -> PR. ParserK INPUT m a
146- satisfy = PR. FROM_PARSER . PRD. satisfy
149+ satisfy = FROM_PARSER . PRD. satisfy
147150
148151{-# INLINE takeWhile #-}
149152takeWhile :: CONSTRAINT_IO => (a -> Bool ) -> PR. ParserK INPUT m ()
150- takeWhile p = PR. FROM_PARSER $ PRD. takeWhile p FL. drain
153+ takeWhile p = FROM_PARSER $ PRD. takeWhile p FL. drain
151154
152155{-# INLINE takeWhileK #-}
153156takeWhileK :: MonadIO m =>
@@ -240,7 +243,7 @@ takeWhileFailD predicate (Fold fstep finitial _ ffinal) =
240243{-# INLINE takeWhileFail #-}
241244takeWhileFail :: CONSTRAINT =>
242245 (a -> Bool ) -> Fold m a b -> PR. ParserK INPUT m b
243- takeWhileFail p f = PR. FROM_PARSER (takeWhileFailD p f)
246+ takeWhileFail p f = FROM_PARSER (takeWhileFailD p f)
244247
245248{-# INLINE alt2 #-}
246249alt2 :: MonadIO m
0 commit comments