@@ -29,9 +29,16 @@ import qualified Data.ByteString.Lazy.Char8 as LBS8
2929decodeInt :: LBS.ByteString -> Maybe Int
3030decodeInt = A.decode
3131
32+decodeString :: LBS.ByteString -> Maybe String
33+decodeString = A.decode
34+
3235decodeScientific :: LBS.ByteString -> Maybe Scientific
3336decodeScientific = A.decode
3437
38+decodeRaw :: LBS.ByteString -> Integer
39+decodeRaw = LBS.foldl' step 0 where
40+ step a b = a * 10 + fromIntegral (b - 48) -- 48 = '0'
41+
3542decodeAtto :: LBS.ByteString -> Maybe Scientific
3643decodeAtto
3744 = parseOnly (scientific <* AttoL.endOfInput)
@@ -94,8 +101,10 @@ main = defaultMain
94101 ]
95102 where
96103 benchPair name input = bgroup name
97− [ bench "Int" $ whnf decodeInt input
104+ [ bench "Int" $ whnf decodeInt input
105+ , bench "RawFold" $ whnf decodeRaw input
98106 , bench "Scientific" $ whnf decodeScientific input
99− , bench "parserA" $ whnf decodeAtto input
100− , bench "parserS" $ whnf decodeAtto8 input
107+ , bench "parserA" $ whnf decodeAtto input
108+ , bench "parserS" $ whnf decodeAtto8 input
109+ , bench "String" $ whnf decodeString $ "\"" <> input <> "\""
101110 ]