You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Module Math.NumberTheory.Moduli.Jacobi contains an interesting helper function:
-- For large Integers, going via Int is much faster than bit-fiddling-- on the Integer, so we do that.evenI::Integrala=>a->Bool
evenI n =fromIntegral n .&.1== (0::Int)
Actually, it was definitely much faster than even from Prelude before GHC 8.4 due to trac 14437. We should check (looking at Core and CMM), whether evenI is still faster. And if it is, push its definition into base for the profit of the whole community.
The text was updated successfully, but these errors were encountered:
$ ghc -O2 Even.hs
[1 of 1] Compiling Main ( Even.hs, Even.o )
Linking Even ...
$ ./Even
100000000
even
6.367393s
100000000
evenI
4.35664s
I looked into CMM. Prelude.even results in remInteger n 2, which is left as is. On contrary, fromIntegral :: Integer -> Word is very cheap and remWord n 2 is optimised to bitwise and.
Module
Math.NumberTheory.Moduli.Jacobi
contains an interesting helper function:Actually, it was definitely much faster than
even
fromPrelude
before GHC 8.4 due to trac 14437. We should check (looking at Core and CMM), whetherevenI
is still faster. And if it is, push its definition intobase
for the profit of the whole community.The text was updated successfully, but these errors were encountered: