git.iko.soy/typeable/attoparsec
on master help sign in
More tweaks to tiny benchmark
commit714672c76f28869aa1b3ad465e642103f1312d7a authorBryan O'Sullivan <bos@serpentine.com> dateThu 4 Mar 2010, 15:56 (17 years ago) parent11b8211
1 file changed+10−5
benchmarks/Tiny.hs+10−5
benchmarks/Tiny.hs+10−5
@@ -6,16 +6,21 @@ import qualified Data.ByteString.Char8 as B
66import qualified Text.Parsec as P
77import qualified Text.Parsec.ByteString as P
88
9−mainA = do
9+attoparsec = do
1010 args <- getArgs
1111 forM_ args $ \arg -> do
1212 input <- B.readFile arg
13− let p = A.parse (A.many (A.many1 A.letter <|> A.many1 A.digit)) input
14− case p `A.feed` B.empty of
13+ case A.parse p input `A.feed` B.empty of
1514 A.Done _ xs -> print (length xs)
1615 what -> print what
16+ where
17+ slow = A.many (A.many1 A.letter <|> A.many1 A.digit)
18+ fast = A.many (A.takeWhile1 isLetter <|> A.takeWhile1 isDigit)
19+ isDigit c = c >= '0' && c <= '9'
20+ isLetter c = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
21+ p = fast
1722
18−mainP = do
23+parsec = do
1924 args <- getArgs
2025 forM_ args $ \arg -> do
2126 input <- readFile arg
@@ -23,4 +28,4 @@ mainP = do
2328 Left err -> print err
2429 Right xs -> print (length xs)
2530
26−main = mainP
31+main = attoparsec