[Haskell-cafe] Speed of character reading in Haskell

Derek Elkins derek.a.elkins at gmail.com
Sun Sep 9 19:58:24 EDT 2007


On Mon, 2007-09-10 at 00:49 +0100, Neil Mitchell wrote:
> Hi
> 
> > > (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
> locks.

A little more and that would have Dr. Seuss-esque.



More information about the Haskell-Cafe mailing list