@param args
(String[] args)
| 21 | * @param args |
| 22 | */ |
| 23 | public static void main(String[] args) { |
| 24 | int trials = 10; // Run code multiple times to compute average time. |
| 25 | double[] times = new double[max]; // Store times |
| 26 | |
| 27 | for (int j = 0; j < trials; j++) { // Run this 10 times to compute |
| 28 | for (int i = 0; i < max; i++) { |
| 29 | fib = new int[max]; |
| 30 | long start = System.currentTimeMillis(); |
| 31 | fibonacci(i); |
| 32 | long end = System.currentTimeMillis(); |
| 33 | long time = end - start; |
| 34 | times[i] += time; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | for (int j = 0; j < max; j++) { |
| 39 | System.out.println(j + ": " + times[j] / trials + "ms"); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | } |