[Haskell-cafe] Speed of character reading in Haskell
ndmitchell at gmail.com
Sun Sep 9 19:49:06 EDT 2007
> > (Some list operations are too expensive with ByteString but for most
> > string processing it's perfectly fine and much faster than String).
> I'm sure it's true, but it's quite irrelevant to my question, which is
> "why is using getChar so much slower than using getContents"?
Buffering, blocks and locks.
Buffering: getChar demands to get a character now, which pretty much
means you can't buffer.
Blocks: getContents reads blocks at a time from the underlying
library, whereas getChar has to do one character at a time.
Locks: getChar has to acquire locks, as does getContents. However,
because getContents can operate on blocks, this requires many fewer
More information about the Haskell-Cafe