Live data from Hacker News

When Haskell is Faster than C

paulspontifications.blogspot.com

21–30 of 119 posts

Re: When Haskell is Faster than C

#21
As always talking about performance differences and optimization without thoroughly profiling and pointing out bottlenecks should be frowned upon big time.

I would really love to see the generated assembly code and see what makes the difference in performance. Anyone up to analyzing?

Re: When Haskell is Faster than C

#22

Hmm... it seems to me that whenever any article is posted that claims "X is faster than C", there are immediately 40 replies saying "Well, the author's C is horrible. If I wrote that, it would be much different." Okay, as someone who has NOT been programming in C 8 hours a day for years on end, I would actually like to see somebody do this -- to show me what GOOD C looks like. So if someone wouldn't mind, could you t…

There already is an efficient multithreaded C version on the shootout site. I don't know if that's what people would consider good production code, but at least it isn't laughably bad.

http://benchmarksgame.alioth.debian.org/u32/program.php?test...

Re: When Haskell is Faster than C

#23
post #7

I'm in no position to judge the quality of the Haskell code (I couldn't program my way out of a wet paper bag in Haskell) but after half a lifetime of writing C for a living I can say with confidence that the C code is horribly written and horribly inefficient. It is tempting to pull the code and fix it. If you want to compare two languages make sure that you are proficient in both.

I agree - if you're comparing runtime implementations.

I think this is actually a useful comparison, though. I would argue it's a lot easier to become a proficient, performance-conscious programmer in python, java, or even Haskell, than C. And you're more likely to shoot yourself in the foot with C.

From the point of view of someone who hasn't learned either language (maybe a scientist or engineer looking to do some simulation work), the message here is, "with the same time and effort, not only is Haskell as fast as C in many cases, but in some cases it will actually be faster than the C code that you, a beginner, can write."

Re: When Haskell is Faster than C

#24
The paragraph beginning with "To put it another way, C is no longer close to the real machine" really drove the point home. The further C gets away from the real machine then the less useful C will become. Higher-level languages have the advantage that a compiler can more easily determine what the program is attempting to accomplish and optimize the result for a specified architecture. This will be very difficult to do for C. As a result I would expect the performance of higher-level languages to start exceeding the performance of C. I guess we're just going to have to change our conventional wisdom when that time comes.

Re: When Haskell is Faster than C

#25

Hmm... it seems to me that whenever any article is posted that claims "X is faster than C", there are immediately 40 replies saying "Well, the author's C is horrible. If I wrote that, it would be much different." Okay, as someone who has NOT been programming in C 8 hours a day for years on end, I would actually like to see somebody do this -- to show me what GOOD C looks like. So if someone wouldn't mind, could you t…

Ok, I pledge to re-write this properly and to benchmark the current implementation vs a nice one. I'll post the results. I need something to get my mind off things and this is as good as any. It will take at least until Monday (it is my sons birthday tomorrow).

Looking forward to seeing your results from this.

Re: When Haskell is Faster than C

#26

Hmm... it seems to me that whenever any article is posted that claims "X is faster than C", there are immediately 40 replies saying "Well, the author's C is horrible. If I wrote that, it would be much different." Okay, as someone who has NOT been programming in C 8 hours a day for years on end, I would actually like to see somebody do this -- to show me what GOOD C looks like. So if someone wouldn't mind, could you t…

Ok, I pledge to re-write this properly and to benchmark the current implementation vs a nice one. I'll post the results. I need something to get my mind off things and this is as good as any. It will take at least until Monday (it is my sons birthday tomorrow).

Subscribing to this.

Re: When Haskell is Faster than C

#27
post #4

The contradiction of "C is always faster than everything" (apparently shown untrue by comparison on the reverse-complement problem) is not "Haskell is faster than C".

Indeed not. The useful point this article makes, I think, is that if you're a good Haskell programmer and a competent C programmer, you can produce working code in both, but you can still produce better-performing code in Haskell.

Essentially, the lesson is that there's little point writing code in C for performance unless you're good at it. If you can write good-enough code in a higher-level language that you're happy with, you might already have reached an optimum.

Re: When Haskell is Faster than C

#28
The program in question copies data from stdin, does the barest minimum of preprocessing, statically remaps all characters, and writes to stdout...

Why on earth is this a demonstration of what Haskell can do effectively? There's no room to exploit anything interesting about type level reasoning.

Re: When Haskell is Faster than C

#29

Earlier quoted context omitted.

I'm no C expert - too bad to hear that about his C code. However I can tell people here that Vector.Unboxed is a very common optimization as soon as you start thinking about performance in Haskell. Nothing "expertly" about it, really. I, for one, use it in all of my computational Haskell code.

Fair enough. My complaint is that the C code isn't given the same chance. He even calls out that reading data with getc is a known performance problem, but then does it anyway. Any book on learning C will point out that getc is slow for reading lots of data, and fscanf or fread should be used instead.

I would never encourage use of the f* I/O functions from the standard C library for high performance code. They're all buffered which means there's an extra copy happening. You should use read and other POSIX I/O functions instead.

Re: When Haskell is Faster than C

#30

Earlier quoted context omitted.

I'm no C expert - too bad to hear that about his C code. However I can tell people here that Vector.Unboxed is a very common optimization as soon as you start thinking about performance in Haskell. Nothing "expertly" about it, really. I, for one, use it in all of my computational Haskell code.

Fair enough. My complaint is that the C code isn't given the same chance. He even calls out that reading data with getc is a known performance problem, but then does it anyway. Any book on learning C will point out that getc is slow for reading lots of data, and fscanf or fread should be used instead.

From what I understood from his post, using a buffered input function would a) make the code differ from the specification, b) require more refactoring than the Haskell code needed. b) seems particularly important when the program is not <100LOC, but tens or hundreds of lines of code.
Post reply on HN