forked from zhenrong-wang/BTAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
207 lines (180 loc) · 7.36 KB
/
main.cpp
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
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cstdint>
#include <tuple>
extern "C" {
#include "filter_uniq_ints.h"
}
#include "filter_uniq_ints_cpp.hpp"
/**
* @brief
* usage: ./command argv[1] argv[2]
* argv[1] indicates the size (number of elems) of the input array
* argv[2] indicates the maximun of the random number generated
* NOTE: argv[2] doesn't affect the Round 2 of benchmark
*
* @returns
* 0 if everything goes well
*
*/
int main(int argc, char** argv) {
int with_brute = 0;
if(argc < 3) {
printf("ERROR: not enough args. USAGE: ./command argv[1] argv[2] argv[3](Optional: brute).\n");
return 1;
}
if (argc > 3 && strcmp(argv[3], "brute") == 0) {
with_brute = 1;
}
unsigned int num_elems = convert_string_to_positive_num(argv[1]), rand_max = convert_string_to_positive_num(argv[2]);
printf("INPUT_ELEMS:\t%u\nRANDOM_MAX:\t%u\n\n",num_elems, rand_max);
if(num_elems < 0 || rand_max < 0) {
printf("ERROR: arguments illegal. Make sure they are plain positive numbers.\n");
return 3;
}
int *arr_input = (int *)malloc(sizeof(int) * num_elems);
if(arr_input == NULL) {
printf("ERROR: Failed to allocate memory for input array.\n");
return 5;
}
int err_flag = 0;
unsigned int num_elems_out = 0;
clock_t start, end;
int *out_naive_improved = NULL, *out_naive = NULL, *out_ht = NULL, *out_ht_new = NULL, *out_ht_dyn = NULL, *out_bit = NULL, *out_bit_stc = NULL;
generate_random_input_arr(arr_input,num_elems,rand_max);
FILE* file_p=fopen("random.csv","wb+");
if(file_p == NULL){
free(arr_input);
return 7;
}
for(unsigned int i = 0; i < num_elems; i++) {
fprintf(file_p, "%d\n", arr_input[i]);
}
fclose(file_p);
printf("RANDOM ARRAY INPUT:\n");
printf("ALGO_TYPE\tTIME_IN_SEC\tUNIQUE_INTEGERS\n");
start = clock();
out_bit = fui_bitmap_base_dyn(arr_input, num_elems, &num_elems_out, &err_flag);
end = clock();
printf("BITMAP_ALGO:\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
free(out_bit);
start = clock();
out_bit_stc = fui_bitmap_stc(arr_input, num_elems, &num_elems_out, &err_flag);
end = clock();
printf("BITMAP_STC:\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
free(out_bit_stc);
start = clock();
out_ht = filter_unique_elems_ht(arr_input, num_elems, &num_elems_out, &err_flag);
end = clock();
printf("HASH_ALGO:\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
free(out_ht);
start = clock();
out_ht_new = filter_unique_elems_ht_new(arr_input, num_elems, &num_elems_out, &err_flag);
end = clock();
printf("HASH_ALGO_NEW:\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
free(out_ht_new);
start = clock();
out_ht_dyn = filter_unique_elems_ht_dyn(arr_input, num_elems, &num_elems_out, &err_flag);
end = clock();
printf("HASH_ALGO_DYN:\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
free(out_ht_dyn);
if(with_brute == 1) {
start = clock();
out_naive_improved = filter_unique_elems_naive_improved(arr_input, num_elems, &num_elems_out, &err_flag);
end = clock();
printf("NAIVE_ALGO_NEW:\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
free(out_naive_improved);
start = clock();
out_naive = filter_unique_elems_naive(arr_input, num_elems, &num_elems_out, &err_flag);
end = clock();
printf("NAIVE_ALGO:\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
free(out_naive);
}
// start = clock();
// std::ignore = cpp::filter_uniq(std::span{arr_input, static_cast<size_t>(num_elems)});
// end = clock();
// printf("CPP:\t\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
{
start = clock();
const auto out = cpp::filter_uniq_sort(std::span{arr_input, static_cast<size_t>(num_elems)});
end = clock();
printf("CPP (SORT):\t%lf\t%lu\n", (double)(end - start)/CLOCKS_PER_SEC, out.size());
}
{
start = clock();
const auto out = cpp::filter_uniq_ht(std::span{arr_input, static_cast<size_t>(num_elems)});
end = clock();
printf("CPP (HT-BIT):\t%lf\t%lu\n", (double)(end - start)/CLOCKS_PER_SEC, out.size());
}
memset(arr_input, 0, num_elems);
generate_growing_arr(arr_input, num_elems);
file_p=fopen("growing.csv","wb+");
if(file_p == NULL){
free(arr_input);
return 7;
}
for(unsigned int i = 0; i < num_elems; i++) {
fprintf(file_p, "%d\n", arr_input[i]);
}
fclose(file_p);
printf("\nGROWING ARRAY INPUT:\n");
printf("ALGO_TYPE\tTIME_IN_SEC\tUNIQUE_INTEGERS\n");
start = clock();
out_bit = fui_bitmap_base_dyn(arr_input, num_elems, &num_elems_out, &err_flag);
end = clock();
printf("BITMAP_ALGO:\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
free(out_bit);
start = clock();
out_bit_stc = fui_bitmap_stc(arr_input, num_elems, &num_elems_out, &err_flag);
end = clock();
printf("BITMAP_STC:\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
free(out_bit_stc);
start = clock();
out_ht = filter_unique_elems_ht(arr_input, num_elems, &num_elems_out, &err_flag);
end = clock();
printf("HASH_ALGO:\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
free(out_ht);
start = clock();
out_ht_new = filter_unique_elems_ht_new(arr_input, num_elems, &num_elems_out, &err_flag);
end = clock();
printf("HASH_ALGO_NEW:\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
free(out_ht_new);
start = clock();
out_ht_dyn = filter_unique_elems_ht_dyn(arr_input, num_elems, &num_elems_out, &err_flag);
end = clock();
printf("HASH_ALGO_DYN:\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
free(out_ht_dyn);
if(with_brute == 1) {
start = clock();
out_naive_improved = filter_unique_elems_naive_improved(arr_input, num_elems, &num_elems_out, &err_flag);
end = clock();
printf("NAIVE_ALGO_NEW:\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
free(out_naive_improved);
start = clock();
out_naive = filter_unique_elems_naive(arr_input, num_elems, &num_elems_out, &err_flag);
end = clock();
printf("NAIVE_ALGO:\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
free(out_naive);
}
// start = clock();
// std::ignore = cpp::filter_uniq(std::span{arr_input, static_cast<size_t>(num_elems)});
// end = clock();
// printf("CPP:\t\t%lf\t%d\n", (double)(end - start)/CLOCKS_PER_SEC, num_elems_out);
{
start = clock();
const auto out = cpp::filter_uniq_sort(std::span{arr_input, static_cast<size_t>(num_elems)});
end = clock();
printf("CPP (SORT):\t%lf\t%lu\n", (double)(end - start)/CLOCKS_PER_SEC, out.size());
}
{
start = clock();
const auto out = cpp::filter_uniq_ht(std::span{arr_input, static_cast<size_t>(num_elems)});
end = clock();
printf("CPP (HT-BIT):\t%lf\t%lu\n", (double)(end - start)/CLOCKS_PER_SEC, out.size());
}
printf("\nBenchmark done.\n\n");
free(arr_input);
return 0;
}