public class ProfileTest2 { static int numTrials; // The number of trials to use in averaging. static int size; // Data (array) size. static int[] data; // The data. static int[] max; // Store partial maximums. // findMax now returns the stored value. static int findMax (int limit) { return max[limit]; } // For sake of comparison, we'll leave this in its original inefficient form. static double findSum (int limit) { double sum = 0; for (int i=0; i m) m = data[i]; // 1.2 Store as k-th partial maximum. max[k] = m; } // 2. Now estimate. double total = 0; // 3. Repeat numTrials times. for (int n=0; n "); System.exit(1); } // Obtain the size of the data. size = Integer.parseInt (argv[0].trim()); // Obtain the number of trials used in averaging. numTrials = Integer.parseInt (argv[1].trim()); // Create random data. createData (); // Estimate the average partial-maximum. estimateMax (); // Estimate the average partial-sum. estimateSum (); } catch (Exception e) { e.printStackTrace(); } } }