[Haskell-cafe] Speed of character reading in Haskell

Bulat Ziganshin bulat.ziganshin at gmail.com
Mon Sep 10 02:30:04 EDT 2007


Hello Neil,

Monday, September 10, 2007, 3:49:06 AM, you wrote:

>> 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.

in ghc, is entirely due to locking, which is the slowest operation in
whole hGetChar algorithm

> Buffering: getChar demands to get a character now, which pretty much
> means you can't buffer.

both uses the same buffering (512 bytes)

> Blocks: getContents reads blocks at a time from the underlying
> library, whereas getChar has to do one character at a time.

i don't see difference between buffering and blocking

> Locks: getChar has to acquire locks, as does getContents. However,
> because getContents can operate on blocks, this requires many fewer
> locks.

getContents doesn't lock Handle because it is supposed to use it in
exclusive manner


-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list