@@ -23,6 +23,7 @@ module Handle.Read
2323 (allBenchmarks )
2424where
2525
26+ import Control.Monad (void )
2627import Data.Char (ord )
2728import Data.Functor.Identity (runIdentity )
2829import Data.Word (Word8 )
@@ -32,11 +33,12 @@ import GHC.Magic (noinline)
3233#else
3334#define noinline
3435#endif
35- import System.IO (Handle )
36+ import System.IO (Handle , hClose , openFile , IOMode ( .. ) )
3637import Prelude hiding (last , length )
3738
3839import qualified Streamly.Data.Fold as FL
3940import qualified Streamly.Data.Unicode.Stream as SS
41+ import qualified Streamly.Internal.Data.Json.Stream as SJ
4042import qualified Streamly.FileSystem.Handle as FH
4143-- import qualified Streamly.Internal.Data.Fold as IFL
4244import qualified Streamly.Internal.Data.Parser as PR
@@ -246,6 +248,24 @@ readDecodeUtf8Lax inh =
246248 $ SS. decodeUtf8Lax
247249 $ S. unfold FH. read inh
248250
251+ readJsonDrain :: Handle -> IO ()
252+ readJsonDrain inh =
253+ void
254+ $ IP. parse SJ. parseJson
255+ $ S. unfold FH. read inh
256+
257+ o_n_space_parse_json :: [Benchmark ]
258+ o_n_space_parse_json =
259+ [ bgroup
260+ " parse/json"
261+ [ bench " parseJson" $
262+ nfIO $ do
263+ inh <- openFile " twitter.json" ReadMode
264+ readJsonDrain inh
265+ hClose inh
266+ ]
267+ ]
268+
249269#ifdef INSPECTION
250270inspect $ hasNoTypeClasses 'readDecodeUtf8 Lax
251271-- inspect $ 'readDecodeUtf8Lax `hasNoType` ''Step
@@ -531,4 +551,5 @@ allBenchmarks env = Prelude.concat
531551 , o_1_space_reduce_read_grouped env
532552 , o_1_space_reduce_read_split env
533553 , o_1_space_reduce_toChunks_split env
554+ , o_n_space_parse_json
534555 ]
0 commit comments