[Haskell-cafe] Is Haskell IO inherently slower than C?

Jake jake.waksbaum at gmail.com
Thu May 5 01:05:37 UTC 2016

I'm trying to write a program in Haskell that writes a large file at the
end, and it seems like that output alone is taking way longer than it
should. I don't understand why Haskell shouldn't be able to write data as
quickly as C, so I wrote two test files:

-- Test.hs
import Control.Loop
import Data.ByteString.Builder
import System.IO

main :: IO ()
main =
  numLoop 0 1000000 $ \_ ->
    hPutBuilder stdout $ char7 ' '

// test.c
#include <stdio.h>

int main() {
  int i;
  for (i = 0; i < 1000000; i++) {
    fprintf(stdout, " ");
  return 0;

I compiled them both with -O2, and ran them redirecting their outputs to
/dev/null. For the Haskell version I got times aroudn 0.3 seconds, while
the C version was around 0.03. Is there any reason why in simple IO the
Haskell version would be slower by an order of magnitude?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160505/a62c3a2f/attachment.html>

More information about the Haskell-Cafe mailing list