<div dir="ltr">I also tried the more standard forM_ [0..100000] idiom and got similar times. I hoped loop might be faster, but apparently not.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, May 4, 2016 at 9:05 PM Jake <<a href="mailto:jake.waksbaum@gmail.com">jake.waksbaum@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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:<div><br></div><div>-- Test.hs</div><div><div>import Control.Loop</div><div>import Data.ByteString.Builder</div><div>import System.IO</div><div><br></div><div>main :: IO ()</div><div>main =</div><div>  numLoop 0 1000000 $ \_ -></div><div>    hPutBuilder stdout $ char7 ' '</div></div><div><br></div><div>// test.c</div><div><div>#include <stdio.h></div><div><br></div><div>int main() {</div><div>  int i;</div><div>  for (i = 0; i < 1000000; i++) {</div><div>    fprintf(stdout, " ");</div><div>  }</div><div>  return 0;</div><div>}</div></div><div><br></div><div>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?</div></div></blockquote></div>