Make exponentiation significantly faster#221
Conversation
|
I've checked core and it looks like unrolling doesn't work as intended. Variants with and without unrolling have similar performance and I've got interested what is exact difference? I'll benchmark it |
|
That's interesting, have you looked at the core that gets produced with known exponents when calling Since the exponent arguments to centralMoments are likely to always be known, it feels like its definition should also be marked INLINE, it's not a large function. While I'm thinking about it, do you know why the definition chooses to use |
|
Lets drop unrolling and then this PR could be merged As it currently stands unrolling doesn't achieve specialization for central momenta of statically known powers. But simply turning |
Tail-recursive variant is much faster
We don't get specialization and gains are relatively small. Let go with simpler solution
539c470 to
0a34059
Compare
|
Thank you! Merged |

From #220, make the
(^)function significantly faster - it does this two ways, by unrolling common low exponents (1-5), which allows GHC to inline the full set of multiplications, and in cases above 5, it uses a tail recursive loop, which is much faster than the non-tail recursive definition that's been in hiding in this package for over a decade (it probably is faster than Prelude's definition, but it's not fast).Benchmarks, adding the 10th and 20th central moment to demonstrate the effect of the loop (I'm sure someone must care about that statistic...). I've only included benchmarks that actually call
(^)