Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigInteger performance for extremely large numbers

I'm thinking about using the BigInteger class to store numbers in the range of 10-1000 MB. Does anyone have experience with this? Are there practical or implied limits for extremely large numbers?

like image 899
mafu Avatar asked Jul 04 '13 11:07

mafu


1 Answers

Well, the documentation for BigInteger says that the numbers can be of any size as long as you have enough memory to handle it.

Regular operations (add, subtract, multiply and so on) on a BigInteger are much slower (at least 50x according to some tests) than regular numeric types, but you can probably live with that.

Also, you must remember that the BigInteger type is immutable, so operations on it will yield a new instance. So adding two 10MB numbers will create a new 10MB number. It will not modify the existing instances. This may have implications for how you structure your code.

The only practical limitations is the amount of memory available on your computer and the amount of memory available to your program. This should be at least 3GB for 32bit processes, more for 64bit, so you should be able to work with the numbers you need.

like image 75
Rune Grimstad Avatar answered Sep 28 '22 09:09

Rune Grimstad