2-- Module : Streamly.Benchmark.Data.Parser
3-- Copyright : (c) 2020 Composewell Technologies
5-- License : BSD-3-Clause
6-- Maintainer : streamly@composewell.com
9{-# LANGUAGE FlexibleContexts #-}
10{-# LANGUAGE ScopedTypeVariables #-}
11{-# OPTIONS_GHC -Wno-orphans #-}
15{-# OPTIONS_GHC -ddump-simpl -ddump-to-file -dsuppress-all #-}
23import Control.DeepSeq (NFData(..))
24import Control.Monad (replicateM_)
25import Streamly.Internal.Data.Parser (ParseError(..))
26import Streamly.Internal.Data.Stream (Stream)
28 (any, all, take, sequence, sequence_, sequenceA, takeWhile, dropWhile)
30import qualified Streamly.Data.Array as Array
31import qualified Streamly.Data.Stream as Stream
32import qualified Streamly.Internal.Unicode.Parser as PRU
34import Gauge hiding (env)
35import Streamly.Benchmark.Common
37runParser :: Int -> (Stream IO Char -> IO a) -> IO ()
39 let v = "+123456789.123456789e-123"
40 let !(arr :: Array.Array Char) = Array.fromListN (length v) v
41 let s = Stream.unfold Array.reader arr
42 replicateM_ count (p s)
44-- | Takes a fold method, and uses it with a default source.
45{-# INLINE benchIOSink #-}
46benchIOSink :: Int -> String -> (Stream IO Char -> IO b) -> Benchmark
47benchIOSink value name f = bench name $ nfIO $ runParser value f
49{-# INLINE doubleParser #-}
50doubleParser :: Monad m => Stream m Char -> m (Either ParseError (Int, Int))
51doubleParser = Stream.parse PRU.doubleParser
54number :: Monad m => Stream m Char -> m (Either ParseError (Integer, Int))
55number = Stream.parse PRU.number
58double :: Monad m => Stream m Char -> m (Either ParseError Double)
59double = Stream.parse PRU.double
61{-# INLINE numberDouble #-}
62numberDouble :: Monad m => Stream m Char -> m (Either ParseError Double)
63numberDouble = Stream.parse p
64 where p = uncurry PRU.mkDouble <$> PRU.number
66-------------------------------------------------------------------------------
68-------------------------------------------------------------------------------
71moduleName = "Unicode.Parser"
73instance NFData ParseError where
75 rnf (ParseError x) = rnf x
77o_n_heap_serial :: Int -> [Benchmark]
78o_n_heap_serial value =
80 benchIOSink value "doubleParser" doubleParser
81 , benchIOSink value "number" number
82 , benchIOSink value "double (doubleParser)" double
83 , benchIOSink value "double (number)" numberDouble
86-------------------------------------------------------------------------------
88-------------------------------------------------------------------------------
93 runWithCLIOpts defaultStreamSize allBenchmarks
98 [ bgroup (o_n_heap_prefix moduleName) (o_n_heap_serial value)
101 -- Enable FUSION_CHECK macro at the beginning of the file
102 -- Enable one benchmark below, and run the benchmark
103 -- Check the .dump-simpl output
105 runParser value double
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list