I was trying out this nice Rust Rayon package and I ended up recalling an infamous microbenchmark I came across just because something rater suspicious came up in my twitter stream: a haskeller proudly claiming that Haskell was beating everyone by an order of magnitude in a concurrency microbenchmark dubbed Skynet.

Digging out the matter I soon came to realize it was yet another case of programming language bias, and got into some argument in the pull request, because... why not 😄?

The microbenchmark went from comparing currency by spawning actors, green threads, goroutines, in several other languages, with this on Haskell:

So, the code has been creatively massaged and reduced to trivial parallelism, using the rpar evaluation strategy even! Which of course would just probably behave like Rayon explains:

Note though that calling join is very different from just spawning two threads in terms of performance. This is because join does not guarantee that the two closures will run in parallel. If all of your CPUs are already busy with other work, Rayon will instead opt to run them sequentially.

And later

This [work stealing] technique is not new. It was first introduced by the Cilk project, done at MIT in the late nineties. The name Rayon is an homage to that work.

This description just fits what a twitter user has warned:

One can possibly assert this is an apple and orange comparison, an unfair one (even more because why it was being that faster was not added to README as part of the pull, just numbers...).

If this is fair so is the following C++ compile time version?

It's so fast!

Well, one may still argue that as it's not "launching" "parallel" tasks, it's not fair.

OK, enough Haskell. Back to bare metal, back to Rust.

By using Rayon we get a Rust version that is just as elegant as the Haskell version:

It's basically the same stuff, and (in my machine at last) it's an order of magnitude faster than the Haskell version! Bare Metal wins again

But, what was more enjoyable in Rust, taking a POV of a beginner, was not having to deal with a bloated building system as the Haskell ecosystem offers, cryptic undocumented packages, cryptic code and extensions, cryptic errors...

Well, I'm indeed rusty in Haskell, since I'm not caring for it anymore, so it was not just a POV, I ended up in trouble with this small snippet because I changed it slightly to adopt other timing functions and forgot to add {-# LANGUAGE OverloadedStrings #-}, I just ended baffled with the error message, got some time to figure it out.