Linux.com

Haskell vs. C++

Link to this post 20 May 09

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?

Link to this post 21 May 09

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.

Link to this post 21 May 09

Thanks. So the primary benefit to Haskell is in source code and structure.... I'll keep that in mind.

Link to this post 21 May 09

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.

Link to this post 22 May 09

"a horrible comparison"
that is absolutely right. no way to compare them.

Link to this post 22 May 09

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.

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board