Okay maybe a silly question here, but I am currently learning haskell by completing problems on projecteuler.net
I ran into an interesting observation and was hoping someone could shed some light why things are the way they are.
For reference, I was implementing Problem #29 Here's what I came up
nub $ [ a^^b | a <- [2..100], b <- [2..100] ]
I observed that using the ^^
operator is faster than **
which is faster than ^
for the input listed above.
My question is simply, why? Each of these operators applies to different type classes. My guess is there is some type conversions taking place, but I would expect ^
to be the faster of the operations, when it seems it's actually the oposite.
Thanks!
All the time is spent on nub
. With ^^
and **
you're doing nub
on [Double]
. With ^
it is nub
on [Integer]
, and comparing big integers is slower than comparing doubles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With