Int vs Word performance?

Claus Reinke claus.reinke at
Thu Feb 26 18:28:48 EST 2009

Looking at prelude/PrelRules.hs has reminded me of an old
conundrum: if I switch from Int to Word, should I expect any
performance differences?

A while ago, I needed lots of fairly small positive numbers,
together with a small number of flags for each, so I thought
I'd switch from Int to Word, and map the flags to bits. But 
the performance dropped so drastically that I went back
to Int, slightly complicating the bitmaps. I didn't expect that,
and I can't see any builtin rules for Int that would have no
Word counterpart.

Here is a trivial example with drastic difference between
T = Int and T = Word (~2.5x here):

    main = print $ foldl' (+) 0 [1..100000000::T]

What am I missing here?

Also, in the real code I ended up seeing things like this in
the -ddump-simpl output for the bit-fiddling code:

            (GHC.Prim.int2Word# wild13_XbE)
            (GHC.Prim.int2Word# y#_a4EZ))

Is that likely to cost me a lot or are these conversions cheap?


More information about the Glasgow-haskell-users mailing list