-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
64 lines (54 loc) · 1.92 KB
/
Main.java
File metadata and controls
64 lines (54 loc) · 1.92 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Vector;
class Main {
public static int NO_OF_TIMES = 1000;
// Returns the kth percentile for the responses.
public int getPercentile(int k) {
double index = NO_OF_TIMES * k /100;
index = Math.abs(index);
return (int)index - 1;
}
// Returns the mean for the responses.
public long getMean(Long[] responses) {
long sum = 0;
for (int i=0; i<responses.length; i++) {
sum += responses[i];
}
return sum / NO_OF_TIMES;
}
// Returns the standar deviation for the responses.
public double getStandarDeviation(Long[] responses, long mean) {
double sumOfDiff = 0;
for (int i=0; i<responses.length; i++) {
double diff = responses[i] - mean;
sumOfDiff += diff * diff;
}
return Math.sqrt(sumOfDiff / NO_OF_TIMES);
}
public static void main(String[] args) throws InterruptedException {
Main m = new Main();
Long[] responses = new Long[NO_OF_TIMES];
Vector<Long> responseTime = new Vector<Long>();
ArrayList<FetchURL> threads = new ArrayList<FetchURL>();
for (int i=0; i<NO_OF_TIMES; i++) {
FetchURL f = new FetchURL(responseTime);
f.start();
threads.add(f);
}
for (FetchURL f : threads) {
f.join();
}
responseTime.toArray(responses);
Arrays.sort(responses);
// Print.
System.out.println("==10th Percentile==" + responses[m.getPercentile(10)]);
System.out.println("==50th Percentile==" + responses[m.getPercentile(50)]);
System.out.println("==90th Percentile==" + responses[m.getPercentile(90)]);
System.out.println("==95th Percentile==" + responses[m.getPercentile(95)]);
System.out.println("==99th Percentile==" + responses[m.getPercentile(99)]);
long mean = m.getMean(responses);
System.out.println("==Mean==" + mean);
System.out.println("==Standard Deviation==" + m.getStandarDeviation(responses, mean));
}
}