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

Jake jake.waksbaum at gmail.com
Thu May 5 01:07:25 UTC 2016


I also tried the more standard forM_ [0..100000] idiom and got similar
times. I hoped loop might be faster, but apparently not.

On Wed, May 4, 2016 at 9:05 PM Jake <jake.waksbaum at gmail.com> wrote:

> 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/183344da/attachment.html>


More information about the Haskell-Cafe mailing list