on master help sign in
Add string and raw foldl' benchmarks
b368f14Oleg Grenrus
benchmarks/Issue673.hs+12−3
@@ -29,9 +29,16 @@ import qualified Data.ByteString.Lazy.Char8 as LBS8
29decodeInt :: LBS.ByteString -> Maybe Int
29decodeInt :: LBS.ByteString -> Maybe Int
30decodeInt = A.decode
30decodeInt = A.decode
31
31
32+decodeString :: LBS.ByteString -> Maybe String
33+decodeString = A.decode
34+
32decodeScientific :: LBS.ByteString -> Maybe Scientific
35decodeScientific :: LBS.ByteString -> Maybe Scientific
33decodeScientific = A.decode
36decodeScientific = A.decode
34
37
38+decodeRaw :: LBS.ByteString -> Integer
39+decodeRaw = LBS.foldl' step 0 where
40+ step a b = a * 10 + fromIntegral (b - 48) -- 48 = '0'
41+
35decodeAtto :: LBS.ByteString -> Maybe Scientific
42decodeAtto :: LBS.ByteString -> Maybe Scientific
36decodeAtto
43decodeAtto
37 = parseOnly (scientific <* AttoL.endOfInput)
44 = parseOnly (scientific <* AttoL.endOfInput)
@@ -94,8 +101,10 @@ main = defaultMain
94 ]
101 ]
95 where
102 where
96 benchPair name input = bgroup name
103 benchPair name input = bgroup name
97− [ bench "Int" $ whnf decodeInt input
104+ [ bench "Int" $ whnf decodeInt input
105+ , bench "RawFold" $ whnf decodeRaw input
98 , bench "Scientific" $ whnf decodeScientific input
106 , bench "Scientific" $ whnf decodeScientific input
99− , bench "parserA" $ whnf decodeAtto input
107+ , bench "parserA" $ whnf decodeAtto input
100− , bench "parserS" $ whnf decodeAtto8 input
108+ , bench "parserS" $ whnf decodeAtto8 input
109+ , bench "String" $ whnf decodeString $ "\"" <> input <> "\""
101 ]
110 ]