[Haskell-cafe] Is Haskell capable of matching C in string processing performance?

John Millikin jmillikin at gmail.com
Fri Jan 22 12:45:37 EST 2010


There's no such thing as "cheating", though that particular code won't
work for my purposes because it assumes the output is merely a stream
of "null". Fine for the benchmark, but not extractable to the full
problem.

I wonder: is Handle known to be particularly slow? This code only has
to work on Linux and BSD, so if using (for example) a POSIX fd would
be much faster, it could bring the Haskell version much closer to C.

On Fri, Jan 22, 2010 at 07:30, Tom Nielsen <tanielsen at gmail.com> wrote:
>> It seems to me this indicates that the big expense here is the call into the I/O system.
>
> So let's make fewer I/O calls:
>
> import Control.Monad
> import qualified Data.ByteString.Char8 as S
> import System.IO
>
> null_str1 = S.concat $ take 1000 $ repeat $ S.pack "null"
>
> n1 = 5000000 `div` 1000
>
> main = withBinaryFile "out3.json" WriteMode $ \h -> do
>  hPutStr h "["
>  replicateM_ n1 (S.hPutStr h null_str1)
>  hPutStr h "]"
> ---
> this is 10x faster. Whether this is cheating or not depends on what
> John actually wants to do.
>
> Tom
>


More information about the Haskell-Cafe mailing list