streamly
streamly copied to clipboard
hPutBuf is expensive, need a better alternative/implementation for faster fileio
See this example . If we compare the C printf with our print statement using hPutBuf it performs poorly.
printName arr off = do
-- If we use an Array then we can use a slice of the same
-- buffer for printing and for passing to loopDir.
MutByteArray.pokeAt off arr (10 :: Word8)
-- hPutBuf is quite expensive compared to C printf.
-- There should be an API that supplies the buffer directly to kernel.
-- And we can build a buffer in the loop here and write it when it is
-- ready.
MutByteArray.unsafeAsPtr arr $ \p ->
hPutBuf stdout p (off+1)
This matters only if we use it too often for small data printing. This is a common case for routine printing on console.