top | item 21267693

(no title)

Sysreq1 | 6 years ago

Throwing multiple cores at the problem is not what I would call beating decades of optimized C. The author only utilizes multiple cores when he realizes the overhead of Haskell will not allow him to actually win. Author even admits the C program was more efficient. You can multi thread a C program as well, at which point it would retake the title.

discuss

order

zelly|6 years ago

It's sad to see this kind of Stockholm syndrome. The author is fighting hard against the Haskell compiler to fit a square peg in a round hole. Programming languages are just tools, not religions. Programming languages are fake abstractions of the machine. When one doesn't work for you, you should have no problem switching to another. Loyalty to literally an arbitrary man-made mental model at the expense of your real life productivity makes zero sense.

pwm|6 years ago

Funny how different people read this differently. I read it as a playful exploration of how far can you push your square peg into that round hole. No one uses Haskell as a faster C irl, that would not make much sense, that’s not where the strength of the language lies.

simias|6 years ago

There seems to be an unhealthy obsession with beating C in some corner of the Haskell community. It makes even less sense nowadays when some of the most popular languages out there are Javascript and Python, clearly C-grade performance is not required anymore by the vast majority of applications.

I actually wrote a comment (in 2013, but the page I'm referencing doesn't appear to have changed one bit) where I shared my experience looking at haskell.org's introduction that was filled with FUD regarding C and how Haskell was so much better and faster:

https://news.ycombinator.com/item?id=5090808

Maybe if they had actually tried to teach me the language instead of that bad faith "used car salesman" tactic I'd be writing Haskell these days.

tom_mellior|6 years ago

> There seems to be an unhealthy obsession with beating C in some corner of the Haskell community.

I think it's about the same for pretty much any language in the "statically typed, compiled" camp. You'll see "faster than C" claims for Rust and Go as well, for example.

Ahri|6 years ago

I've immersed myself in the Haskell community for the past couple of years and while I'd agree that a few posts try to race a Haskell implementation against a C version, these are in the extreme minority.

I feel that you have mis-characterised a whole community, very few of whom care to make Haskell faster than C and overwhelmingly share your view that "C-grade performance is not required".

Further, in the posts I've read of people comparing to C, if anything C is held up as the benchmark as a mark of respect - not as something to cheat against, not to try to say that Haskell is better. Indeed Haskell's FFI out to C is really nice, and demonstrates the pragmatic side of this ivory-tower language :)

This post first embraces its clickbait article and then highlights that even though the Haskell version may be faster on multicore systems (at least for ascii - the unicode version may be incorrect wrt. unicode spaces), but that in practical situations without caching this may not provide any benefit. You're acting as if OP submitted his binary to Apple, *BSD and all the Linux distros with a pull request saying his is better! It's a fun post golfing some Haskell performance issues.

Annatar|6 years ago

C-like performance is required more than ever: we have to have monster multicore machines with gigabytes of memory just to run any software. That's absolutely ridiculous.

MrBuddyCasino|6 years ago

I have noticed this is a very human pattern. Things have their strengths, and they've got their weaknesses. But if your identity is bound too much to your favourite thing, you have to bend reality in order to make the weakness disappear.

Or as Feynman put it:

The first principle is that you must not fool yourself — and you are the easiest person to fool.

psychoslave|6 years ago

The article starts directly with a warning that the title is a bit provocative.

The main point here is clearly not to sell the existing tool on the sole consideration of binary execution performances. As the article say, with Haskell you can produce more reliable software, thanks to a strong typing, and use higher abstraction levels. Even with a significant loss in performance, this can be a good trade off (depending on the project type of course).

So the point here is that you can have descent performance with a state of the art "high-level garbage-collected runtime-based language".

erichocean|6 years ago

> is a bit provocative

"is wildly incorrect" would be more accurate.

bonzini|6 years ago

Also, when counting words the C code is actually handling multibyte sequences, which is one of the biggest sources of improvement for the Haskell code (8s to 3.5s).

Having to use a syntax extension explicitly to forgo laziness feels like cheating to me... But then I have never used Haskell so perhaps that's actually normal.

unhammer|6 years ago

If you're talking about BANGPATTERNS, that is completely normal in Haskell.

Pretty much any non-trivial Haskell program (and many trivial ones too) will have !'s in various places to force something to be strict, and to use the ! syntax you do need to add a pragma. Those pragmas are what let Haskell evolve new features without breaking backward compatibility, so Haskell programs tend to have a lot of them. Perhaps one day we'll have a new standard (it's been 19 years since the last one) which will include some of the pragmas by default. In the meanwhile, it's possible to turn the common ones on project-wide and just forget about them.

pcstl|6 years ago

Haskell is a lazy-by-default language and the most practical way to disable laziness is that syntax extension.

You can do it without the extension, but it'll turn ugly really quick (lots of uses of the "seq" function everywhere).

In general, the Haskell community is very tolerant of language extensions (people will recommend you enable about a dozen of them in every project), so this is pretty standard.

tome|6 years ago

> Having to use a syntax extension explicitly to forgo laziness feels like cheating to me... But then I have never used Haskell so perhaps that's actually normal.

The `seq` function achieves the same end and is in the standard library. There's nothing cheating about it. The bang patterns extension just provides some nicer syntax for it.

ummonk|6 years ago

In fairness, throwing multiple cores at it would require a lot more boilerplate in C.

Whereas for single-core the C code would be simpler than the optimized single-core Haskell code presented here.

vkazanov|6 years ago

Structured concurrency with OpenMP can be very convenient at times... :-)

gpderetta|6 years ago

#pragma omp for

Goes a long way.

InvOfSmallC|6 years ago

What is the cost of parallelism of C though?

rootw0rm|6 years ago

spinning up threads and context switching, just like the cost for everyone else?

raverbashing|6 years ago

Whatever the cost in C, Haskell is incurring the same cost, unless it is using green threads.

(You could use green threads in C - or something similar, though to be honest counting words in a file is a bit of an annoying problem for parallelism)