Data.Text for parsec3

Kazu Yamamoto ( 山本和彦 ) kazu at
Wed Feb 9 06:58:51 CET 2011

>> No. What kind of benchmark is appealing? Comparing it with ByteString?
> I think comparing it to String would be a better choice; at the very
> least the Text version should be no worse than String.


I wrote a parser to extract word of a pattern and parsed an ASCII file
of about 6 Mbytes(concatenated *.texi files of Emacs). I measured
performance with the time command. The compiler is GHC 6.12.3 with -O.

  String:           7.34s user 0.69s system 99% cpu 8.040 total
  Lazy ByteString:  9.95s user 0.60s system 99% cpu 10.549 total
  Lazy Text:       10.74s user 1.09s system 91% cpu 12.967 total

Lazy Text is slower than String. But Lazy ByteString is also slow.
Yes, this is not a good result. But there is no reason to merge the
patch of Text.


Here is my code:

target :: Parser String
target = appear samp 

-- to extract @samp{} of GNU's texi
samp :: Parser String
samp = string "@samp{" *> many1 (noneOf "}") <* char '}'

appear :: Parser a -> Parser [a]
appear p = (:) <$> try p <*> appear p
       <|> anyChar *> appear p
       <|> [] <$ eof

More information about the Libraries mailing list