-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
173 lines (140 loc) · 4.12 KB
/
Copy pathmain.cpp
File metadata and controls
173 lines (140 loc) · 4.12 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
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
#include <time.h>
#include <iostream>
#include "Sets.h"
#include "Logger.h"
char* set_gen();
int main(int argc, char **argv) {
using namespace std;
srand(time(NULL));
char st_A [ArraySet::SET_POWER + 1] {"012"};
char st_B [ArraySet::SET_POWER + 1] {"1356"};
char st_C [ArraySet::SET_POWER + 1] {"2895"};
char st_D [ArraySet::SET_POWER + 1] {"0126985"};
ArraySet A {st_A};
ArraySet B {st_B};
ArraySet C {st_C};
ArraySet D {st_D};
ArraySet E {};
cout << "Input: " << endl;
cout << A << endl
<< B << endl
<< C << endl
<< D << endl;
E = A | (B & C & D);
cout << "Result: " << endl;
cout << E << endl;
char choice = 0;
cout << "Generate, input from keyboard or run benchmark? (G\\K\\B) ";
cin >> choice;
if (choice == 'G' || choice == 'g') {
A = set_gen();
B = set_gen();
C = set_gen();
D = set_gen();
}
else if (choice == 'K' || choice == 'k') {
cout << "Type hexadecimal numbers in one string, without duplicates." << endl;
cout << "Set A: ";
cin >> st_A;
cout << "Set B: ";
cin >> st_B;
cout << "Set C: ";
cin >> st_C;
cout << "Set D: ";
cin >> st_D;
}
else if (choice == 'B' || choice == 'b') {
enum {REPEAT_NUM = 10000};
ArraySet arr_A {st_A};
ArraySet arr_B {st_B};
ArraySet arr_C {st_C};
ArraySet arr_D {st_D};
ArraySet arr_E {};
unsigned long start_time = clock();
for (int z = 0; z < REPEAT_NUM; z++) {
arr_E = arr_A | (arr_B & arr_C & arr_D);
}
unsigned long finish_time = clock();
double arr_time = (finish_time - start_time)/* / static_cast<double>(REPEAT_NUM)*/;
ListSet list_A {st_A};
ListSet list_B {st_B};
ListSet list_C {st_C};
ListSet list_D {st_D};
ListSet list_E {};
start_time = clock();
for (int z = 0; z < REPEAT_NUM; z++) {
list_E = list_A | (list_B & list_C & list_D);
}
finish_time = clock();
double list_time = (finish_time - start_time)/* / static_cast<double>(REPEAT_NUM)*/;
BitSet bits_A {st_A};
BitSet bits_B {st_B};
BitSet bits_C {st_C};
BitSet bits_D {st_D};
BitSet bits_E {};
start_time = clock();
for (int z = 0; z < REPEAT_NUM; z++) {
bits_E = bits_A | (bits_B & bits_C & bits_D);
}
finish_time = clock();
double bits_time = (finish_time - start_time) /*/ static_cast<double>(REPEAT_NUM)*/;
cout << "Array time: " << arr_time << endl;
cout << "Lists clocks: " << list_time << endl;
cout << "Bits clocks: " << bits_time << endl;
return 0;
}
// ARRAYS
ArraySet arr_A {st_A};
ArraySet arr_B {st_B};
ArraySet arr_C {st_C};
ArraySet arr_D {st_D};
ArraySet arr_E {arr_A | (arr_B & arr_C & arr_D)};
cout << "Sets as arrays: " << endl;
cout << "Input: " << endl;
arr_A.show();
arr_B.show();
arr_C.show();
arr_D.show();
cout << "Result: " << endl;
arr_E.show();
// LIST
ListSet list_A {st_A};
ListSet list_B {st_B};
ListSet list_C {st_C};
ListSet list_D {st_D};
ListSet list_E {list_A | (list_B & list_C & list_D)};
cout << "Sets as lists: " << endl;
cout << "Input: " << endl;
list_A.show();
list_B.show();
list_C.show();
list_D.show();
cout << "Result: " << endl;
list_E.show();
// BIT ARRAY
BitSet bits_A {st_A};
BitSet bits_B {st_B};
BitSet bits_C {st_C};
BitSet bits_D {st_D};
BitSet bits_E {bits_A | (bits_B & bits_C & bits_D)};
cout << "Sets as bits: " << endl;
cout << "Input: " << endl;
bits_A.show();
bits_B.show();
bits_C.show();
bits_D.show();
cout << "Result: " << endl;
bits_E.show();
return 0;
}
char* set_gen()
{
char* A = new char[ArraySet::SET_POWER + 1];
char mask[] = "0123456789ABCDEF";
int j = 0;
for (int i = 0; i < 15; i++)
if (rand() % 2 == 1)
A[j++] = mask[i];
A[j] = '\0';
return A;
}