on master help sign in
Bench Parser.scientific, and attoparsec variant
commit47e07b9d6b279aaaeed93c5c6e708a8a62021696 authorOleg Grenrus <oleg.grenrus@iki.fi> dateFri 12 Oct 2018, 16:30 (8 years ago) parent139972e
2 files changed+22
benchmarks/Issue673.hs+21 benchmarks/aeson-benchmarks.cabal+1
benchmarks/Issue673.hs+21
@@ -18,7 +18,10 @@ import Criterion.Main
1818import Prelude.Compat
1919import Data.Int (Int64)
2020import Data.Scientific (Scientific)
21+import Data.Aeson.Parser (scientific)
2122
23+import qualified Data.Attoparsec.ByteString.Lazy as AttoL
24+import qualified Data.Attoparsec.ByteString.Char8 as Atto8
2225import qualified Data.Aeson as A
2326import qualified Data.ByteString.Lazy as LBS
2427import qualified Data.ByteString.Lazy.Char8 as LBS8
@@ -29,6 +32,22 @@ decodeInt = A.decode
2932decodeScientific :: LBS.ByteString -> Maybe Scientific
3033decodeScientific = A.decode
3134
35+decodeAtto :: LBS.ByteString -> Maybe Scientific
36+decodeAtto
37+ = parseOnly (scientific <* AttoL.endOfInput)
38+ where
39+ parseOnly p lbs = case AttoL.parse p lbs of
40+ AttoL.Done _ r -> Just r
41+ AttoL.Fail _ _ _ -> Nothing
42+
43+decodeAtto8 :: LBS.ByteString -> Maybe Scientific
44+decodeAtto8
45+ = parseOnly (Atto8.scientific <* AttoL.endOfInput)
46+ where
47+ parseOnly p lbs = case AttoL.parse p lbs of
48+ AttoL.Done _ r -> Just r
49+ AttoL.Fail _ _ _ -> Nothing
50+
3251generate :: Int64 -> LBS.ByteString
3352generate n = LBS8.replicate n '1'
3453
@@ -77,4 +96,6 @@ main = defaultMain
7796 benchPair name input = bgroup name
7897 [ bench "Int" $ whnf decodeInt input
7998 , bench "Scientific" $ whnf decodeScientific input
99+ , bench "parserA" $ whnf decodeAtto input
100+ , bench "parserS" $ whnf decodeAtto8 input
80101 ]
benchmarks/aeson-benchmarks.cabal+1
@@ -333,6 +333,7 @@ executable aeson-issue-673
333333 ghc-options: -Wall -O1 -rtsopts
334334 build-depends:
335335 aeson-benchmarks,
336+ attoparsec,
336337 base,
337338 bytestring,
338339 scientific,