git.iko.soy/typeable/attoparsec
on master help sign in
Add scan benchmark
commit0bd74649a32106860f9c9c216dec6b3946711046 authorJohan Tibell <johan.tibell@gmail.com> dateTue 13 Nov 2012, 14:45 (14 years ago) parent00ce9c9
1 file changed+16−1
benchmarks/Benchmarks.hs+16−1
benchmarks/Benchmarks.hs+16−1
@@ -19,6 +19,7 @@ import qualified Data.ByteString.Char8 as BC
1919import qualified Data.ByteString.Lazy as BL
2020import qualified Data.Text as T
2121import qualified Data.Text.Lazy as TL
22+import Data.Word (Word8)
2223import qualified Text.Parsec as P
2324
2425instance NFData ByteString where
@@ -74,6 +75,7 @@ main = do
7475 , bench "isAlpha_iso8859_15" $ nf (ABL.parse (AC.takeWhile AC.isAlpha_iso8859_15)) bl
7576 ]
7677 , bench "word32LE" $ nf (AB.parse word32LE) b
78+ , bench "scan" $ nf (AB.parse quotedString) b
7779 ]
7880
7981-- Benchmarks bind and (potential) bounds-check merging.
@@ -86,4 +88,17 @@ word32LE = do
8688 return $! (fromIntegral w1 :: Word32) +
8789 fromIntegral w2 `unsafeShiftL` 8 +
8890 fromIntegral w3 `unsafeShiftL` 16 +
89− fromIntegral w4 `unsafeShiftL` 32
91+ fromIntegral w4 `unsafeShiftL` 32
92+
93+doubleQuote, backslash :: Word8
94+doubleQuote = 34
95+backslash = 92
96+{-# INLINE backslash #-}
97+{-# INLINE doubleQuote #-}
98+
99+-- | Parse a string without a leading quote.
100+quotedString :: AB.Parser B.ByteString
101+quotedString = AB.scan False $ \s c -> if s then Just False
102+ else if c == doubleQuote
103+ then Nothing
104+ else Just (c == backslash)