Basic I/O performance in Haskell

后端 未结 3 767
别跟我提以往
别跟我提以往 2021-01-03 08:31

Another microbenchmark: Why is this \"loop\" (compiled with ghc -O2 -fllvm, 7.4.1, Linux 64bit 3.2 kernel, redirected to /dev/null)



        
3条回答
  •  死守一世寂寞
    2021-01-03 08:44

    On my (rather slow and outdated) machine the results are:

    $ time haskell-test > haskell-out.txt
    real    1m57.497s
    user    1m47.759s
    sys     0m9.369s
    $ time c-test > c-out.txt
    real    7m28.792s
    user    1m9.072s
    sys     6m13.923s
    $ diff haskell-out.txt c-out.txt
    $
    

    (I have fixed the list so that both C and Haskell start with 0).

    Yes you read this right. Haskell is several times faster than C. Or rather, normally buffered Haskell is faster than C with write(2) non-buffered syscall.

    (When measuring output to /dev/null instead of a real disk file, C is about 1.5 times faster, but who cares about /dev/null performance?)

    Technical data: Intel E2140 CPU, 2 cores, 1.6 GHz, 1M cache, Gentoo Linux, gcc4.6.1, ghc7.6.1.

提交回复
热议问题