Though it does not often get mentioned in the Haskell community, simply
bumping to a new version of GHC can drastically improve the performance of your
code. Here, I have several examples from my
fast-arithmetic
package, which will hopefully give an idea of just how much work has gone into
optimizing code produced by GHC.
Computation | Compiler Version | Time |
---|---|---|
isPrime 2017 |
8.4.2 | 427.0 ns |
isPrime 2017 |
8.2.2 | 424.1 ns |
isPrime 2017 |
8.0.2 | 428.8 ns |
isPrime 2017 |
7.10.3 | 771.2 ns |
factorial 160 |
8.4.2 | 5.632 μs |
factorial 160 |
8.2.2 | 5.658 μs |
factorial 160 |
8.0.2 | 6.202 μs |
factorial 160 |
7.10.3 | 7.424 μs |
totient 3018 |
8.4.2 | 352.7 ns |
totient 3018 |
8.2.2 | 401.4 ns |
totient 3018 |
8.0.2 | 413.3 ns |
totient 3018 |
7.10.3 | 369.9 ns |
I don't really have any grand conclusions here, other than "upgrade your compiler." It is an easy optimization given the payoff.