forked from ArkScript-lang/Ark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAckermann.java
More file actions
47 lines (39 loc) · 1.35 KB
/
Ackermann.java
File metadata and controls
47 lines (39 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.Arrays;
public class Ackermann {
public static int ack(int m, int n) {
if (m > 0) {
if (n == 0) {
return ack(m - 1, 1);
} else {
return ack(m - 1, ack(m, n - 1));
}
} else {
return n + 1;
}
}
public static void main(String args[]) {
long[] results = new long[125];
for (int i=0; i < 125; ++i) {
long startTime = System.nanoTime() / 1000;
ack(3, 6);
long stopTime = System.nanoTime() / 1000;
results[i] = stopTime - startTime;
System.out.println("Run time: " + (stopTime - startTime));
}
double mean = 0.0;
for (long a : results)
mean += a;
mean /= 125;
System.out.println("Mean time: " + mean + "us");
Arrays.sort(results);
if (results.length % 2 == 0)
System.out.println("Median time: " + (results[(results.length / 2) - 1] + results[results.length / 2]) / 2.0 + "us");
else
System.out.println("Median time: " + results[results.length / 2] + "us");
double temp = 0.0;
for (long a : results)
temp += (a - mean) * (a - mean);
double stddev = Math.sqrt(temp / 125);
System.out.println("Stddev: " + stddev + "us");
}
}