S
Stefan Ram
Calculating the remainder of a java.math.BigInteger object
seems to be slow. For a number > 100, it would be sufficient
and possibly faster to just extract the two least significant
digits and compare them with »00«. But I can not directly
access the internal representation of a java.math.BigInteger
object. Does anyone see a possibility to accelerate such a
divisibility test for a java.math.BigInteger object using the
same tricks one uses when testing this by mental arithmetic?
(This is not premature optimization. I already have a program
that is too slow, and a profiler showed that it spends a
significant amount of time in java.math.BigInteger.remainder:
java.math.BigInteger.remainder 1.35 %
java.math.BigInteger.<init> 1.01 %
java.math.BigInteger.add 1.01 %
java.math.BigInteger.divide 0.68 %
java.math.BigInteger.valueOf 0.68 %
java.math.BigInteger.subtract 0.34 %
java.math.BigInteger.multiply 0.34 %
Because the profiler also includes program startup and other
phases of the process, the percentage of the
java.math.BigInteger.remainder operation is larger then shown
above when put in relation to the actual calculation phase.)
seems to be slow. For a number > 100, it would be sufficient
and possibly faster to just extract the two least significant
digits and compare them with »00«. But I can not directly
access the internal representation of a java.math.BigInteger
object. Does anyone see a possibility to accelerate such a
divisibility test for a java.math.BigInteger object using the
same tricks one uses when testing this by mental arithmetic?
(This is not premature optimization. I already have a program
that is too slow, and a profiler showed that it spends a
significant amount of time in java.math.BigInteger.remainder:
java.math.BigInteger.remainder 1.35 %
java.math.BigInteger.<init> 1.01 %
java.math.BigInteger.add 1.01 %
java.math.BigInteger.divide 0.68 %
java.math.BigInteger.valueOf 0.68 %
java.math.BigInteger.subtract 0.34 %
java.math.BigInteger.multiply 0.34 %
Because the profiler also includes program startup and other
phases of the process, the percentage of the
java.math.BigInteger.remainder operation is larger then shown
above when put in relation to the actual calculation phase.)