-
Notifications
You must be signed in to change notification settings - Fork 0
/
MergeSortTest.java
183 lines (160 loc) · 5.3 KB
/
MergeSortTest.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import static org.junit.Assert.*;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import org.junit.Test;
public class MergeSortTest {
private Integer lowerRange = 0;
private Integer higherRange = 1000000000;
@Test
public void TimeTest10() {
int N = 10;
int seedCount = (int)(N*.20); // 20%
long seeds[] = new long[seedCount];
for(int i=0; i<seedCount; i++)
seeds[i] = i;
Random rand = new Random();
int ranks[] = new int[N];
for(int i=0; i<N; i++) {
// setting a seed
int seedIndex = rand.nextInt(seedCount);
rand.setSeed(seeds[seedIndex]);
ranks[i] = rand.nextInt(higherRange+1);
// ranks[i] = ThreadLocalRandom.current().nextInt(lowerRange, higherRange+1);
}
long startTime = System.currentTimeMillis();
MergeSort m = new MergeSort();
m.sort(ranks, 0, N-1);
long endTime = System.currentTimeMillis();
System.out.println("TimeTest10 : "+(endTime - startTime)+" milliseconds");
}
@Test
public void TimeTest50() {
int N = 50;
int ranks[] = new int[N];
for(int i=0; i<N; i++) {
ranks[i] = ThreadLocalRandom.current().nextInt(lowerRange, higherRange+1);
}
long startTime = System.currentTimeMillis();
MergeSort m = new MergeSort();
m.sort(ranks, 0, N-1);
long endTime = System.currentTimeMillis();
System.out.println("TimeTest50 : "+(endTime - startTime)+" milliseconds");
}
@Test
public void TimeTest100() {
int N = 100;
int ranks[] = new int[N];
for(int i=0; i<N; i++) {
ranks[i] = ThreadLocalRandom.current().nextInt(lowerRange, higherRange+1);
}
long startTime = System.currentTimeMillis();
MergeSort m = new MergeSort();
m.sort(ranks, 0, N-1);
long endTime = System.currentTimeMillis();
System.out.println("TimeTest100 : "+(endTime - startTime)+" milliseconds");
}
@Test
public void TimeTest200() {
int N = 200;
int ranks[] = new int[N];
for(int i=0; i<N; i++) {
ranks[i] = ThreadLocalRandom.current().nextInt(lowerRange, higherRange+1);
}
long startTime = System.currentTimeMillis();
MergeSort m = new MergeSort();
m.sort(ranks, 0, N-1);
long endTime = System.currentTimeMillis();
System.out.println("TimeTest200 : "+(endTime - startTime)+" milliseconds");
}
@Test
public void TimeTest300() {
int N = 300;
int ranks[] = new int[N];
for(int i=0; i<N; i++) {
ranks[i] = ThreadLocalRandom.current().nextInt(lowerRange, higherRange+1);
}
long startTime = System.currentTimeMillis();
MergeSort m = new MergeSort();
m.sort(ranks, 0, N-1);
long endTime = System.currentTimeMillis();
System.out.println("TimeTest300 : "+(endTime - startTime)+" milliseconds");
}
@Test
public void TimeTest400() {
int N = 400;
int ranks[] = new int[N];
for(int i=0; i<N; i++) {
ranks[i] = ThreadLocalRandom.current().nextInt(lowerRange, higherRange+1);
}
long startTime = System.currentTimeMillis();
MergeSort m = new MergeSort();
m.sort(ranks, 0, N-1);
long endTime = System.currentTimeMillis();
System.out.println("TimeTest400 : "+(endTime - startTime)+" milliseconds");
}
@Test
public void TimeTest1000() {
int N = 1000;
int ranks[] = new int[N];
for(int i=0; i<N; i++) {
ranks[i] = ThreadLocalRandom.current().nextInt(lowerRange, higherRange+1);
}
long startTime = System.currentTimeMillis();
MergeSort m = new MergeSort();
m.sort(ranks, 0, N-1);
long endTime = System.currentTimeMillis();
System.out.println("TimeTest1000 : "+(endTime - startTime)+" milliseconds");
}
@Test
public void TimeTest5000() {
int N = 5000;
int ranks[] = new int[N];
for(int i=0; i<N; i++) {
ranks[i] = ThreadLocalRandom.current().nextInt(lowerRange, higherRange+1);
}
long startTime = System.currentTimeMillis();
MergeSort m = new MergeSort();
m.sort(ranks, 0, N-1);
long endTime = System.currentTimeMillis();
System.out.println("TimeTest5000 : "+(endTime - startTime)+" milliseconds");
}
@Test
public void TimeTest10000() {
int N = 10000;
int ranks[] = new int[N];
for(int i=0; i<N; i++) {
ranks[i] = ThreadLocalRandom.current().nextInt(lowerRange, higherRange+1);
}
long startTime = System.currentTimeMillis();
MergeSort m = new MergeSort();
m.sort(ranks, 0, N-1);
long endTime = System.currentTimeMillis();
System.out.println("TimeTest10000 : "+(endTime - startTime)+" milliseconds");
}
@Test
public void TimeTest50000() {
int N = 50000;
int ranks[] = new int[N];
for(int i=0; i<N; i++) {
ranks[i] = ThreadLocalRandom.current().nextInt(lowerRange, higherRange+1);
}
long startTime = System.currentTimeMillis();
MergeSort m = new MergeSort();
m.sort(ranks, 0, N-1);
long endTime = System.currentTimeMillis();
System.out.println("TimeTest50000 : "+(endTime - startTime)+" milliseconds");
}
@Test
public void TimeTest100000() {
int N = 100000;
int ranks[] = new int[N];
for(int i=0; i<N; i++) {
ranks[i] = ThreadLocalRandom.current().nextInt(lowerRange, higherRange+1);
}
long startTime = System.currentTimeMillis();
MergeSort m = new MergeSort();
m.sort(ranks, 0, N-1);
long endTime = System.currentTimeMillis();
System.out.println("TimeTest100000 : "+(endTime - startTime)+" milliseconds ");
}
}