-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestRandom.java
60 lines (48 loc) · 1.83 KB
/
TestRandom.java
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
48
49
50
51
52
53
54
55
56
57
58
59
60
import org.checkpoint.*;
class BeforeHook extends Hook {
String str;
BeforeHook(String s) {
str = s;
}
public void run() {
System.out.println("Hook:Before Checkpoint: " + str);
}
}
class AfterHook extends Hook {
String str;
AfterHook(String s) {
str = s;
}
public void run() {
System.out.println("Hook:After Restore: " + str);
}
}
public class TestRandom {
public static void main(String[] args) {
if (args.length != 2) System.out.println("Usage: please provide upper bound and sample size");
int upperBound = Integer.parseInt(args[0]);
long sampleSize = Long.parseLong(args[1]);
long testarray[] = new long[upperBound];
for (long i = 0; i < sampleSize; i++) {
Double r = Math.random() * upperBound;
int v = (int) Math.floor(r);
testarray[v] += 1;
}
// CheckpointRestore.CheckTheWorld();
long end = System.currentTimeMillis();
String dir = "./run" + end;
CheckpointRestore.RegisterCheckpointHook(new BeforeHook("Restore Command: As root java -cp ./:./checkpoint.jar -XX:+UseSerialGC -XX:-UsePerfData TestRandomRestore " + dir ));
CheckpointRestore.RegisterRestoreHook(new AfterHook("That's all folks"));
CheckpointRestore.SaveTheWorld(dir);
long max = 0; long min = upperBound; long average = 0;
for (int i = 0; i < upperBound; i++) {
long s = testarray[i];
if (s > max) { max = s;}
if (s < min) { min = s;}
average = average + s;
}
double median = average / upperBound;
System.out.println("Testing random number generator with upper bound = " + upperBound + " and sample size " + sampleSize);
System.out.println("Max bin size = " + max + " Min bin size = " + min + " median bin size = " + median);
}
}