Welcome to the Linux Foundation Forum!

Haskell vs. C++

I have been learning C++, and I now know much of the general syntax. Right now, I am concentrating on learning more of the Standard Template Library. However, I have also learned a bit of Haskell, not nearly as much, and I am interested by it.

So, my question is, what are the basic performance differences that I would generally see if I used Haskell instead of C++, in regards to memory and speed?

Comments

  • samjh
    samjh Posts: 5
    http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&lang=gpp&lang2=ghc&box=1

    According to those benchmarks, C++ is up to 5 times faster, and uses as little as quarter of the memory compared to Haskell.
  • Thanks. So the primary benefit to Haskell is in source code and structure.... I'll keep that in mind.
  • suhaaktas
    suhaaktas Posts: 1
    "a horrible comparison"
    that is absolutely right. no way to compare them.
  • samjh
    samjh Posts: 5
    Ormaaj wrote:
    That is a horrible comparison. It really depends upon how the code is written. Highly optimized C will have a tendency to be faster than GHC, but there are many notable exceptions. Compilers for functional languages have been really pushing ahead as far as automatic code optimization.
    "Notable exceptions" are irrelevant. He is talking about basic performance differences generally observable between the two languages, not specific performance differences in specialised problem domains.

    Haskell is a niche language, not a general purpose language. It is also an interpreted language, which are generally much slower than compiled languages. Again, exceptions need not apply. We're talking about general performance characteristics.

    The benchmark I linked to is not authoritative. But I do not know of any other cross-language benchmark which uses: open-source compilers and interpreters, transparent testing methods and algorithms, well-known algorithms, and algorithms that are fully language-agnostic. For the purposes of basic, generalised performance comparisons between languages, it is a reasonably good benchmark. If a user wants to compare performance differences within a specific problem domain, they'll need to perform benchmark tests themselves.
  • igouy
    igouy Posts: 3
    > depends upon how the code is written

    Then look at how the code is written!

    The full source code, compile options and output is shown for all the programs.
  • igouy
    igouy Posts: 3
    Is there no way to compare "apples" to "oranges'?
  • igouy
    igouy Posts: 3
    > Haskell is a niche language, not a general purpose language. It is also an interpreted language...


    GHC is a Haskell compiler.

    You can see the compilation command and options in each programs "build & benchmark results" log, for example - http://shootout.alioth.debian.org/u32q/benchmark.php?test=spectralnorm&lang=ghc&id=1#log.


    Here's a C interpreter - http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=cint - does that make C an interpreted language?
  • CptPicard
    CptPicard Posts: 1
    The hugely important distinctions are not in some performance benchmarks, but in the fact that Haskell is a pure-functional language, which makes it in general behave and feel much more different than your typical run of the mill imperative OOP language.

    It makes you think rather differently about your solutions (not "how", but "what"), and I would suggest that a lot of functional-style solutions to problems are actually quite enlightening. In addition pure-functionality has important theoretical properties that make it much more amenable to something like data-parallelism due to lack of side-effects, for example...

Categories

Upcoming Training