import java.math.BigInteger; /** This class is used to tune the crossovers for Karatsuba and Toom-Cook multiplication for BigInteger. */ public class BigIntTiming { public static void main(String args[]) { BigInteger a=new BigInteger("3"); BigInteger b=a.pow(200000); BigInteger c=new BigInteger("3"); BigInteger d=c.pow(100001); BigInteger r=BigInteger.ZERO; BigInteger result = b.multiply(d); long e,s, min, diff; min=10000000; System.out.println("Karatsuba\tToom-Cook"); for (int k=10; k<=80; k+=5) for (int t=k; t<=200 && t<=3*k; t+=5) { BigInteger.KARATSUBA_THRESHOLD=k; BigInteger.TOOM_COOK_THRESHOLD=t; s = System.currentTimeMillis(); for (int i=1; i<20; i++) { r = b.multiply(d); } e = System.currentTimeMillis(); diff = e-s; System.out.print(k + "\t" + t + "\t" + diff); if (diff < min) { min = diff; System.out.println("\t*"); } else System.out.println(); if (! r.equals(result)) System.out.println("Result mismatch!"); } } }