Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What performance can I expect from Int32 and Int64?

I often see pprograms like this, where Int64 is an absolute performance killer on 32-bit platforms. My question is now:

If I need a specific word length for my task (in my case a RNG), is Int64 efficient on 64-bit platforms or will it still use the C-calls? And how efficient is converting an Int64 to an Int?

like image 349
fuz Avatar asked Jan 04 '11 07:01

fuz


2 Answers

on a 64bit system Int64 should be fine, I don't know for sure though.

More importantly if you're doing Crypto or random-number-generation you MUST use the data type that the algorithm says to use, also be careful of signed-ness. If you do-not do this you will have the wrong results, which might mean that your cryptography is not secure or your random number generator is not really random (RNGs are hard, and many look random but aren't).

For any other type of work use Integer wherever you can, or even better, make your program polymorphic using the Integral type-class. Then if you think your program is slower than it should be profile it to determine where you should concentrate when you try to speed it up. if you use the Integral type-class changing from Integer to Int is easy. Haskell should be smart enough to specialize (most) code that uses polymorphism to avoid overheads.

like image 138
Paul Bone Avatar answered Oct 05 '22 18:10

Paul Bone


Interesting article on 64 bit performance here:

Isn’t my code going to be faster on 64-bit???

As the article states, the big bottleneck isn't the processor, it's the cache and memory I/O.

like image 21
Robinson Avatar answered Oct 05 '22 18:10

Robinson