Skip to content

Commit ec4f205

Browse files
author
pranaysashank
committed
Add benchmark for parseJson.
1 parent 3ffb2fd commit ec4f205

File tree

2 files changed

+15504
-1
lines changed

2 files changed

+15504
-1
lines changed

benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module Handle.Read
2323
(allBenchmarks)
2424
where
2525

26+
import Control.Monad (void)
2627
import Data.Char (ord)
2728
import Data.Functor.Identity (runIdentity)
2829
import 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(..))
3637
import Prelude hiding (last, length)
3738

3839
import qualified Streamly.Data.Fold as FL
3940
import qualified Streamly.Data.Unicode.Stream as SS
41+
import qualified Streamly.Internal.Data.Json.Stream as SJ
4042
import qualified Streamly.FileSystem.Handle as FH
4143
-- import qualified Streamly.Internal.Data.Fold as IFL
4244
import 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
250270
inspect $ hasNoTypeClasses 'readDecodeUtf8Lax
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

Comments
 (0)