-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUnionFind_Main.java
46 lines (36 loc) · 1.18 KB
/
UnionFind_Main.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
import java.util.Random;
/**
* Author : 13152
* Date : 2020/2/9
* Time : 17:42
* Version : 1.0.0
**/
public class UnionFind_Main {
public static double test(UF uf, int m) {
int size = uf.getSize();
Random random = new Random();
long startTime = System.nanoTime();
for (int i = 0; i < m; i++) {
int a = random.nextInt(size);
int b = random.nextInt(size);
uf.unionElements(a, b);
}
for (int i = 0; i < m; i++) {
int a = random.nextInt(size);
int b = random.nextInt(size);
uf.isConnect(a, b);
}
long endTime = System.nanoTime();
return (endTime - startTime) / 1000000000.0;
}
public static void main(String[] args) {
int size = 1000000;
int m = 1000000;
UnionFind_v3 uf3 = new UnionFind_v3(size);
System.out.println("UnionFind_v3 : " + test(uf3, m) + " s");
UnionFind_v4 uf4 = new UnionFind_v4(size);
System.out.println("UnionFind_v4 : " + test(uf4, m) + " s");
UnionFind_v5 uf5 = new UnionFind_v5(size);
System.out.println("UnionFind_v5 : " + test(uf5, m) + " s");
}
}