-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.h
364 lines (293 loc) · 15.9 KB
/
Timer.h
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
//
// Created by Kamil Bonkowski on 10/04/2021.
//
#ifndef DATASTRUCTURES_TIMER_H
#define DATASTRUCTURES_TIMER_H
#include <string>
using namespace std;
class Timer {
static Timer *instance;
Timer() {
}
public:
static Timer *getInstance() {
if (!instance)
instance = new Timer;
return instance;
}
double avg_time_addToArrayList_Beginning = 0;
double avg_time_addToArrayList_Middle = 0;
double avg_time_addToArrayList_End = 0;
double avg_time_removeFromArrayList_Beginning = 0;
double avg_time_removeFromArrayList_Middle = 0;
double avg_time_removeFromArrayList_End = 0;
double avg_time_findInArrayList_by_index = 0;
double avg_time_findInArrayList_by_value = 0;
double avg_time_addToLinkedList_Beginning = 0;
double avg_time_addToLinkedList_Middle = 0;
double avg_time_addToLinkedList_End = 0;
double avg_time_removeFromLinkedList_Beginning = 0;
double avg_time_removeFromLinkedList_Middle = 0;
double avg_time_removeFromLinkedList_End = 0;
double avg_time_findInLinkedList_by_value = 0;
double avg_time_addToHeap = 0;
double avg_time_removeFromHeap = 0;
double avg_time_findInHeap_by_index = 0;
double avg_time_findInHeap_by_value = 0;
double avg_time_addTo_RB_tree = 0;
double avg_time_remove_from_RB_tree = 0;
double avg_time_find_in_RB_tree = 0;
double elapsed_time_total_arr_1 = 0;
double visit_counter_arr_1 = 0;
double elapsed_time_total_arr_2 = 0;
double visit_counter_arr_2 = 0;
double elapsed_time_total_arr_3 = 0;
double visit_counter_arr_3 = 0;
double elapsed_time_total_arr_4 = 0;
double visit_counter_arr_4 = 0;
double elapsed_time_total_arr_5 = 0;
double visit_counter_arr_5 = 0;
double elapsed_time_total_arr_6 = 0;
double visit_counter_arr_6 = 0;
double elapsed_time_total_arr_7 = 0;
double visit_counter_arr_7 = 0;
double elapsed_time_total_arr_8 = 0;
double visit_counter_arr_8 = 0;
double elapsed_time_total_list_1 = 0;
double visit_counter_list_1 = 0;
double elapsed_time_total_list_2 = 0;
double visit_counter_list_2 = 0;
double elapsed_time_total_list_3 = 0;
double visit_counter_list_3 = 0;
double elapsed_time_total_list_4 = 0;
double visit_counter_list_4 = 0;
double elapsed_time_total_list_5 = 0;
double visit_counter_list_5 = 0;
double elapsed_time_total_list_6 = 0;
double visit_counter_list_6 = 0;
double elapsed_time_total_list_7 = 0;
double visit_counter_list_7 = 0;
double elapsed_time_total_heap_1 = 0;
double visit_counter_heap_1 = 0;
double elapsed_time_total_heap_2 = 0;
double visit_counter_heap_2 = 0;
double elapsed_time_total_heap_3 = 0;
double visit_counter_heap_3 = 0;
double elapsed_time_total_heap_4 = 0;
double visit_counter_heap_4 = 0;
double elapsed_time_total_RB_1 = 0;
double visit_counter_RB_1 = 0;
double elapsed_time_total_RB_2 = 0;
double visit_counter_RB_2 = 0;
double elapsed_time_total_RB_3 = 0;
double visit_counter_RB_3 = 0;
public:
void showAvgTime(string operation
) {
if (operation == "ADD_TO_ARRAYLIST_BEGINNING") {
cout << "Average Time [" << operation << "] : " << avg_time_addToArrayList_Beginning << " ns" << endl;
} else if (operation == "ADD_TO_ARRAYLIST_MIDDLE") {
cout << "Average Time [" << operation << "] : " << avg_time_addToArrayList_Middle << " ns" << endl;
} else if (operation == "ADD_TO_ARRAYLIST_END") {
cout << "Average Time [" << operation << "] : " << avg_time_addToArrayList_End << " ns" << endl;
} else if (operation == "REMOVE_FROM_ARRAYLIST_BEGINNING") {
cout << "Average Time [" << operation << "] : " << avg_time_removeFromArrayList_Beginning << " ns" << endl;
} else if (operation == "REMOVE_FROM_ARRAYLIST_MIDDLE") {
cout << "Average Time [" << operation << "] : " << avg_time_removeFromArrayList_Middle << " ns" << endl;
} else if (operation == "REMOVE_FROM_ARRAYLIST_END") {
cout << "Average Time [" << operation << "] : " << avg_time_removeFromArrayList_End << " ns" << endl;
} else if (operation == "FIND_IN_ARRAYLIST_BY_INDEX") {
cout << "Average Time [" << operation << "] : " << avg_time_findInArrayList_by_index << " ns" << endl;
} else if (operation == "FIND_IN_ARRAYLIST_BY_VALUE") {
cout << "Average Time [" << operation << "] : " << avg_time_findInArrayList_by_value << " ns" << endl;
}
//LINKED LIST
else if (operation == "ADD_TO_LINKEDLIST_BEGINNING") {
cout << "Average Time [" << operation << "] : " << avg_time_addToLinkedList_Beginning << " ns" << endl;
} else if (operation == "ADD_TO_LINKEDLIST_MIDDLE") {
cout << "Average Time [" << operation << "] : " << avg_time_addToLinkedList_Middle << " ns" << endl;
} else if (operation == "ADD_TO_LINKEDLIST_END") {
cout << "Average Time [" << operation << "] : " << avg_time_addToLinkedList_End << " ns" << endl;
} else if (operation == "REMOVE_FROM_LINKEDLIST_BEGINNING") {
cout << "Average Time [" << operation << "] : " << avg_time_removeFromLinkedList_Beginning << " ns" << endl;
} else if (operation == "REMOVE_FROM_LINKEDLIST_MIDDLE") {
cout << "Average Time [" << operation << "] : " << avg_time_removeFromLinkedList_Middle << " ns" << endl;
} else if (operation == "REMOVE_FROM_LINKEDLIST_END") {
cout << "Average Time [" << operation << "] : " << avg_time_removeFromLinkedList_End << " ns" << endl;
} else if (operation == "FIND_IN_LINKEDLIST_BY_VALUE") {
cout << "Average Time [" << operation << "] : " << avg_time_findInLinkedList_by_value << " ns" << endl;
}
//HEAP
else if (operation == "ADD_TO_HEAP") { //1
cout << "Average Time [" << operation << "] : " << avg_time_addToHeap << " ns" << endl;
} else if (operation == "REMOVE_FROM_HEAP") { //2
cout << "Average Time [" << operation << "] : " << avg_time_removeFromHeap << " ns" << endl;
} else if (operation == "FIND_IN_HEAP_BY_INDEX") { //3
cout << "Average Time [" << operation << "] : " << avg_time_findInHeap_by_index << " ns" << endl;
} else if (operation == "FIND_IN_HEAP_BY_VALUE") { //3
cout << "Average Time [" << operation << "] : " << avg_time_findInHeap_by_value << " ns" << endl;
}
//RED BLACK TREE
else if (operation == "ADD_TO_RED_BLACK_TREE") {
cout << "Average Time [" << operation << "] : " << avg_time_addTo_RB_tree << " ns" << endl;
} else if (operation == "REMOVE_FROM_RED_BLACK_TREE") {
cout << "Average Time [" << operation << "] : " << avg_time_remove_from_RB_tree << " ns" << endl;
} else if (operation == "FIND_IN_RED_BLACK_TREE") {
cout << "Average Time [" << operation << "] : " << avg_time_find_in_RB_tree << " ns" << endl;
}
}
public:
void calculate_average_elapsed_time(double elapsed_time, string operation) {
//ARRAY LIST
if (operation == "ADD_TO_ARRAYLIST_BEGINNING") { //1
visit_counter_arr_1++;
elapsed_time_total_arr_1 += elapsed_time;
avg_time_addToArrayList_Beginning = (elapsed_time_total_arr_1 / visit_counter_arr_1);
} else if (operation == "ADD_TO_ARRAYLIST_MIDDLE") { //2
visit_counter_arr_2++;
elapsed_time_total_arr_2 += elapsed_time;
avg_time_addToArrayList_Middle = (elapsed_time_total_arr_2 / visit_counter_arr_2);
} else if (operation == "ADD_TO_ARRAYLIST_END") { //3
visit_counter_arr_3++;
elapsed_time_total_arr_3 += elapsed_time;
avg_time_addToArrayList_End = (elapsed_time_total_arr_3 / visit_counter_arr_3);
} else if (operation == "REMOVE_FROM_ARRAYLIST_BEGINNING") { //4
visit_counter_arr_4++;
elapsed_time_total_arr_4 += elapsed_time;
avg_time_removeFromArrayList_Beginning = (elapsed_time_total_arr_4 / visit_counter_arr_4);
} else if (operation == "REMOVE_FROM_ARRAYLIST_MIDDLE") { //5
visit_counter_arr_5++;
elapsed_time_total_arr_5 += elapsed_time;
avg_time_removeFromArrayList_Middle = (elapsed_time_total_arr_5 / visit_counter_arr_5);
} else if (operation == "REMOVE_FROM_ARRAYLIST_END") { //6
visit_counter_arr_6++;
elapsed_time_total_arr_6 += elapsed_time;
avg_time_removeFromArrayList_End = (elapsed_time_total_arr_6 / visit_counter_arr_6);
} else if (operation == "FIND_IN_ARRAYLIST_BY_INDEX") { //7
visit_counter_arr_7++;
elapsed_time_total_arr_7 += elapsed_time;
avg_time_findInArrayList_by_index = (elapsed_time_total_arr_7 / visit_counter_arr_7);
} else if (operation == "FIND_IN_ARRAYLIST_BY_VALUE") { //8
visit_counter_arr_8++;
elapsed_time_total_arr_8 += elapsed_time;
avg_time_findInArrayList_by_value = (elapsed_time_total_arr_8 / visit_counter_arr_8);
}
//LINKED LIST
else if (operation == "ADD_TO_LINKEDLIST_BEGINNING") { //1
visit_counter_list_1++;
elapsed_time_total_list_1 += elapsed_time;
avg_time_addToLinkedList_Beginning = (elapsed_time_total_list_1 / visit_counter_list_1);
} else if (operation == "ADD_TO_LINKEDLIST_MIDDLE") { //2
visit_counter_list_2++;
elapsed_time_total_list_2 += elapsed_time;
avg_time_addToLinkedList_Middle = (elapsed_time_total_list_2 / visit_counter_list_2);
} else if (operation == "ADD_TO_LINKEDLIST_END") { //3
visit_counter_list_3++;
elapsed_time_total_list_3 += elapsed_time;
avg_time_addToLinkedList_End = (elapsed_time_total_list_3 / visit_counter_list_3);
} else if (operation == "REMOVE_FROM_LINKEDLIST_BEGINNING") { //4
visit_counter_list_4++;
elapsed_time_total_list_4 += elapsed_time;
avg_time_removeFromLinkedList_Beginning = (elapsed_time_total_list_4 / visit_counter_list_4);
} else if (operation == "REMOVE_FROM_LINKEDLIST_MIDDLE") { //5
visit_counter_list_5++;
elapsed_time_total_list_5 += elapsed_time;
avg_time_removeFromLinkedList_Middle = (elapsed_time_total_list_5 / visit_counter_list_5);
} else if (operation == "REMOVE_FROM_LINKEDLIST_END") { //6
visit_counter_list_6++;
elapsed_time_total_list_6 += elapsed_time;
avg_time_removeFromLinkedList_End = (elapsed_time_total_list_6 / visit_counter_list_6);
} else if (operation == "FIND_IN_LINKEDLIST_BY_VALUE") { //7
visit_counter_list_7++;
elapsed_time_total_list_7 += elapsed_time;
avg_time_findInLinkedList_by_value = (elapsed_time_total_list_7 / visit_counter_list_7);
}
//HEAP
else if (operation == "ADD_TO_HEAP") { //1
visit_counter_heap_1++;
elapsed_time_total_heap_1 += elapsed_time;
avg_time_addToHeap = (elapsed_time_total_heap_1 / visit_counter_heap_1);
} else if (operation == "REMOVE_FROM_HEAP") { //2
visit_counter_heap_2++;
elapsed_time_total_heap_2 += elapsed_time;
avg_time_removeFromHeap = (elapsed_time_total_heap_2 / visit_counter_heap_2);
} else if (operation == "FIND_IN_HEAP_BY_INDEX") { //3
visit_counter_heap_3++;
elapsed_time_total_heap_3 += elapsed_time;
avg_time_findInHeap_by_index = (elapsed_time_total_heap_3 / visit_counter_heap_3);
} else if (operation == "FIND_IN_HEAP_BY_VALUE") { //4
visit_counter_heap_4++;
elapsed_time_total_heap_4 += elapsed_time;
avg_time_findInHeap_by_value = (elapsed_time_total_heap_4 / visit_counter_heap_4);
}
//RED BLACK TREE
else if (operation == "ADD_TO_RED_BLACK_TREE") { //1
visit_counter_RB_1++;
elapsed_time_total_RB_1 += elapsed_time;
avg_time_addTo_RB_tree = (elapsed_time_total_RB_1 / visit_counter_RB_1);
} else if (operation == "REMOVE_FROM_RED_BLACK_TREE") { //2
visit_counter_RB_2++;
elapsed_time_total_RB_2 += elapsed_time;
avg_time_remove_from_RB_tree = (elapsed_time_total_RB_2 / visit_counter_RB_2);
} else if (operation == "FIND_IN_RED_BLACK_TREE") { //3
visit_counter_RB_3++;
elapsed_time_total_RB_3 += elapsed_time;
avg_time_find_in_RB_tree = (elapsed_time_total_RB_3 / visit_counter_RB_3);
}
}
void clear_data() {
avg_time_addToArrayList_Beginning = 0;
avg_time_addToArrayList_Middle = 0;
avg_time_addToArrayList_End = 0;
avg_time_removeFromArrayList_Beginning = 0;
avg_time_removeFromArrayList_Middle = 0;
avg_time_removeFromArrayList_End = 0;
avg_time_findInArrayList_by_index = 0;
avg_time_findInArrayList_by_value = 0;
avg_time_addToLinkedList_Beginning = 0;
avg_time_addToLinkedList_Middle = 0;
avg_time_addToLinkedList_End = 0;
avg_time_removeFromLinkedList_Beginning = 0;
avg_time_removeFromLinkedList_Middle = 0;
avg_time_removeFromLinkedList_End = 0;
avg_time_findInLinkedList_by_value = 0;
avg_time_addToHeap = 0;
avg_time_removeFromHeap = 0;
avg_time_findInHeap_by_index = 0;
avg_time_findInHeap_by_value = 0;
avg_time_addTo_RB_tree = 0;
avg_time_remove_from_RB_tree = 0;
avg_time_find_in_RB_tree = 0;
}
void view_data() {
cout << "Average time of operations: " << endl;
cout << endl;
cout << "ADD_TO_ARRAYLIST_BEGINNING: " << avg_time_addToArrayList_Beginning << " ns" << endl;
cout << "ADD_TO_ARRAYLIST_MIDDLE: " << avg_time_addToArrayList_Middle << " ns" << endl;
cout << "ADD_TO_ARRAYLIST_END: " << avg_time_addToArrayList_End << " ns" << endl;
cout << "REMOVE_FROM_ARRAYLIST_BEGINNING: " << avg_time_removeFromArrayList_Beginning << " ns" << endl;
cout << "REMOVE_FROM_ARRAYLIST_MIDDLE: " << avg_time_removeFromArrayList_Middle << " ns" << endl;
cout << "REMOVE_FROM_ARRAYLIST_END: " << avg_time_removeFromArrayList_End << " ns" << endl;
cout << "FIND_IN_ARRAYLIST_BY_INDEX: " << avg_time_findInArrayList_by_index << " ns" << endl;
cout << "FIND_IN_ARRAYLIST_BY_VALUE: " << avg_time_findInArrayList_by_value << " ns" << endl;
cout << endl;
cout << "ADD_TO_LINKEDLIST_BEGINNING: " << avg_time_addToLinkedList_Beginning << " ns" << endl;
cout << "ADD_TO_LINKEDLIST_MIDDLE: " << avg_time_addToLinkedList_Middle << " ns" << endl;
cout << "ADD_TO_LINKEDLIST_END: " << avg_time_addToLinkedList_End << " ns" << endl;
cout << "REMOVE_FROM_LINKEDLIST_BEGINNING: " << avg_time_removeFromLinkedList_Beginning << " ns" << endl;
cout << "REMOVE_FROM_LINKEDLIST_MIDDLE: " << avg_time_removeFromLinkedList_Middle << " ns" << endl;
cout << "REMOVE_FROM_LINKEDLIST_END: " << avg_time_removeFromLinkedList_End << " ns" << endl;
cout << "FIND_IN_LINKEDLIST_BY_VALUE: " << avg_time_findInLinkedList_by_value << " ns" << endl;
cout << endl;
cout << "ADD_TO_HEAP: " << avg_time_addToHeap << " ns" << endl;
cout << "REMOVE_FROM_HEAP: " << avg_time_removeFromHeap << " ns" << endl;
cout << "FIND_IN_HEAP_BY_INDEX: " << avg_time_findInHeap_by_index << " ns" << endl;
cout << "FIND_IN_HEAP_BY_VALUE: " << avg_time_findInHeap_by_value << " ns" << endl;
cout << endl;
cout << "ADD_TO_RED_BLACK_TREE: " << avg_time_addTo_RB_tree << " ns" << endl;
cout << "REMOVE_FROM_RED_BLACK_TREE: " << avg_time_remove_from_RB_tree << " ns" << endl;
cout << "FIND_IN_RED_BLACK_TREE: " << avg_time_find_in_RB_tree << " ns" << endl;
cout << endl;
}
};
#endif //DATASTRUCTURES_TIMER_H