News for hackers. Stuff that matters.
Re:Beating Decades of Optimized C with 80 Lines of Haskell by Sysreq1 on Wednesday October 16, 2019 @02:40AM (#21267693)
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.
Re:Beating Decades of Optimized C with 80 Lines of Haskell by zelly on Wednesday October 16, 2019 @04:27AM (#21268236)
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.
Re:Beating Decades of Optimized C with 80 Lines of Haskell by pwm on Wednesday October 16, 2019 @12:45PM (#21272446)
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.
Re:Beating Decades of Optimized C with 80 Lines of Haskell by simias on Wednesday October 16, 2019 @05:30AM (#21268556)
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.

Re:Beating Decades of Optimized C with 80 Lines of Haskell by tom_mellior on Wednesday October 16, 2019 @05:56AM (#21268685)
> 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.

Re:Beating Decades of Optimized C with 80 Lines of Haskell by simias on Wednesday October 16, 2019 @06:58AM (#21269032)
That's true. I guess what makes Haskell stand out to me is that at this point it's fairly clear that the assertion is mostly wrong (i.e. idiomatic Haskell is not faster than idiomatic C at most algorithmic tasks, and often significantly slower) and instead of doing the reasonable thing and saying "additional safety and expressiveness is more important than raw performance for most applications" (something I'd completely agree with personally) they double-down with these meaningless, unfair benchmarks.

Meanwhile Rust is genuinely competitive with C performance-wise and thanks to generics and things like more aggressive inlining can actually equal or even beat C without requiring esoteric micro-optimizations. Of course the drawback is that writing Rust code is significantly more complicated and more restrictive.

Re:Beating Decades of Optimized C with 80 Lines of Haskell by Annatar on Wednesday October 16, 2019 @07:20AM (#21269163)
And the really funny part for us C practitioners is, we know we'll rarely be as fast as machine code generated from Fortran.
Re:Beating Decades of Optimized C with 80 Lines of Haskell by Ahri on Wednesday October 16, 2019 @01:17PM (#21272844)
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.

Re:Beating Decades of Optimized C with 80 Lines of Haskell by Annatar on Wednesday October 16, 2019 @07:19AM (#21269153)
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.
Re:Beating Decades of Optimized C with 80 Lines of Haskell by MrBuddyCasino on Wednesday October 16, 2019 @04:00AM (#21268088)
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.

Re:Beating Decades of Optimized C with 80 Lines of Haskell by psychoslave on Wednesday October 16, 2019 @04:29AM (#21268242)
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".

Re:Beating Decades of Optimized C with 80 Lines of Haskell by erichocean on Wednesday October 16, 2019 @04:31AM (#21268253)
> is a bit provocative

"is wildly incorrect" would be more accurate.

Re:Beating Decades of Optimized C with 80 Lines of Haskell by psychoslave on Wednesday October 16, 2019 @04:55AM (#21268379)
That sounds like a rather common strategy for making provocative statements, doesn't it?
Re:Beating Decades of Optimized C with 80 Lines of Haskell by bonzini on Wednesday October 16, 2019 @02:44AM (#21267704)
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.

Re:Beating Decades of Optimized C with 80 Lines of Haskell by unhammer on Wednesday October 16, 2019 @02:51AM (#21267742)
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.

Re:Beating Decades of Optimized C with 80 Lines of Haskell by klodolph on Wednesday October 16, 2019 @04:57AM (#21268385)
> …it's been 19 years since the last one…

Does Haskell 2010 not count?

Re:Beating Decades of Optimized C with 80 Lines of Haskell by unhammer on Wednesday October 16, 2019 @03:45PM (#21274660)
doh! 9 of course, thanks
Re:Beating Decades of Optimized C with 80 Lines of Haskell by pcstl on Wednesday October 16, 2019 @10:22AM (#21270617)
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.

Re:Beating Decades of Optimized C with 80 Lines of Haskell by tome on Wednesday October 16, 2019 @03:03AM (#21267814)
> 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.

Re:Beating Decades of Optimized C with 80 Lines of Haskell by ummonk on Wednesday October 16, 2019 @04:29AM (#21268245)
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.

Re:Beating Decades of Optimized C with 80 Lines of Haskell by vkazanov on Wednesday October 16, 2019 @04:46AM (#21268326)
Structured concurrency with OpenMP can be very convenient at times... :-)
Re:Beating Decades of Optimized C with 80 Lines of Haskell by gpderetta on Wednesday October 16, 2019 @04:43AM (#21268310)
#pragma omp for

Goes a long way.

Re:Beating Decades of Optimized C with 80 Lines of Haskell by ummonk on Wednesday October 16, 2019 @11:53AM (#21271756)
Hah, I take it back then...
Re:Beating Decades of Optimized C with 80 Lines of Haskell by InvOfSmallC on Wednesday October 16, 2019 @02:49AM (#21267728)
What is the cost of parallelism of C though?
Re:Beating Decades of Optimized C with 80 Lines of Haskell by rootw0rm on Wednesday October 16, 2019 @03:07AM (#21267830)
spinning up threads and context switching, just like the cost for everyone else?
Re:Beating Decades of Optimized C with 80 Lines of Haskell by chii on Wednesday October 16, 2019 @04:02AM (#21268096)
The Haskell version is provably going to work without issue when parrellelized (due to monoid laws), but I doubt the concurrency primitives in C is as trivially usable, and I expect no sane person would want to write that version.
Re:Beating Decades of Optimized C with 80 Lines of Haskell by cormacrelf on Wednesday October 16, 2019 @05:26AM (#21268542)
There's nothing stopping you from following the monoid laws in C. There is also nothing stopping you from breaking the monoid laws in Haskell.
Re:Beating Decades of Optimized C with 80 Lines of Haskell by sasasassy on Wednesday October 16, 2019 @05:09AM (#21268437)
OpenMP IS trivially usable.
Re:Beating Decades of Optimized C with 80 Lines of Haskell by keldaris on Wednesday October 16, 2019 @04:36AM (#21268275)
Why? This is not a hard problem and there's nothing wrong with parallelism in C. I'd much rather work on parallelizing the C code than deal with any amount of Haskell. I suspect there are more people who would agree with me than the total amount of people happy to write Haskell.
Re:Beating Decades of Optimized C with 80 Lines of Haskell by raverbashing on Wednesday October 16, 2019 @04:13AM (#21268150)
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)

Re:Beating Decades of Optimized C with 80 Lines of Haskell by pcstl on Wednesday October 16, 2019 @10:24AM (#21270648)
Haskell does use green threads. The thing is, Haskell code is managed by a Haskell runtime, and each runtime manages a single (processor) thread. So the usual parallelism model for Haskell is to spawn a runtime for each processor core and then let each runtime manage its own green threads.