[Haskell-cafe] Is Haskell IO inherently slower than C?
Mike Izbicki
mike at izbicki.me
Thu May 5 01:18:15 UTC 2016
You need to be doing tests that take much longer to accurately compare
runtimes of executables. Here's why:
Haskell programs have a more complicated run time system than C
programs, and the binaries output by GHC are much larger. Therefore,
there will be a small additional overhead that you have to pay once
when the program starts. For some machines, this could possibly be on
the order of 0.3 seconds.
I'd recommend you scale your test so that it takes at least 30 seconds
for the slowest program. This will give you more meaningful results.
On Wed, May 4, 2016 at 6:07 PM, Jake <jake.waksbaum at gmail.com> wrote:
> 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?
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list