package username.analysis; import java.io.PrintWriter; import java.math.BigDecimal; /** * A class that helps analyze the various exponentiation algorithms. * * @author Samuel A. Rebelsky * @version 1.0 of April 2006 */ public class AnalyzeExpt { // +-----------+----------------------------------------------- // | Constants | // +-----------+ /** * The number of times to repeat a tests so that too-quick tests * aren't too fast too measure. */ private static final double REPETITIONS = 1000.0; // +-------+--------------------------------------------------- // | Tests | // +-------+ public static void main(String[] args) throws Exception { BigDecimal x; PrintWriter pen = new PrintWriter(System.out, true); Analyst eryn = new Analyst(); Mathematician emily = new Mathematician(eryn); // Try a variety of exponents for (int n = 0; n < 1000; n = n*2+1) { // Try a variety of bases for (int i = 0; i <= 6; i++) { x = new BigDecimal(((double) i) / 2); eryn.reset(); for (int rep = 0; rep < REPETITIONS; rep++) { BigDecimal result = emily.exptFor(x,n); } // for eryn.stop(); pen.println("x: " + x + "\tn: " + n + "\tsteps: " + eryn.steps()/REPETITIONS + "\ttime: " + eryn.elapsed()/REPETITIONS ); } // for each base } // for each exponent } // main(String[]) } // class AnalyzeExpt