1+ import 'UnionFind1.dart' ;
2+ import 'UnionFind2.dart' ;
3+ import 'UnionFind3.dart' ;
4+ import 'UnionFind4.dart' ;
5+ import 'UnionFind5.dart' ;
6+ import 'UnionFind6.dart' ;
7+ import 'dart:math' ;
8+ import 'UF.dart' ;
9+
10+ double testUF (UF uf, int m){
11+
12+ int ? size = uf.getSize ();
13+ Random random = new Random ();
14+
15+ var now = new DateTime .now ();
16+ num startTime = now.millisecondsSinceEpoch;
17+
18+
19+ for (int i = 0 ; i < m ; i ++ ){
20+ int a = random.nextInt (size! );
21+ int b = random.nextInt (size);
22+ uf.unionElements (a, b);
23+ }
24+
25+ for (int i = 0 ; i < m ; i ++ ){
26+ int a = random.nextInt (size! );
27+ int b = random.nextInt (size);
28+ uf.isConnected (a, b);
29+ }
30+
31+ var endNow = new DateTime .now ();
32+ num endTime = endNow.millisecondsSinceEpoch;
33+
34+ double time = (endTime - startTime) / 1000.0 ;
35+ return time;
36+ }
37+
38+ void main (){
39+ int size = 10000000 ;
40+ int m = 10000000 ;
41+
42+ UnionFind3 uf3 = new UnionFind3 (size);
43+ print ("UnionFind3 : ${testUF (uf3 , m )} s" );
44+
45+ UnionFind4 uf4 = new UnionFind4 (size);
46+ print ("UnionFind4 : ${testUF (uf4 , m )} s" );
47+
48+ UnionFind5 uf5 = new UnionFind5 (size);
49+ print ("UnionFind5 : ${testUF (uf5 , m )} s" );
50+
51+ UnionFind6 uf6 = new UnionFind6 (size);
52+ print ("UnionFind6 : ${testUF (uf6 , m )} s" );
53+
54+ }
0 commit comments