-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
71 lines (64 loc) · 2.16 KB
/
main.cpp
File metadata and controls
71 lines (64 loc) · 2.16 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
#include "utils.h"
#include <numeric>
#include <cstring>
#include <cmath>
#include <csv_writer.h>
# define r 2
int main(int argc, char *argv[] )
{
// define variables
long elapsed_time;
std::vector<int> answers;
std::string algorithm_name;
std::string source_string, pattern;
int algorithm_number = atoi(argv[1]);
std::vector<std::tuple<std::string, std::string>> data;
CSVWriter csv;
csv.newRow() << "Algorithm" << "Input_Data_Length"<< "Work_Time";
bool benchmark_flag = false;
if (algorithm_number == 1)
{
algorithm_name = "Rabin-Karp ";
}
else if (algorithm_number == 2)
{
algorithm_name = "Knuth-Morris-Pratt ";
}
if (argc > 2)
{
benchmark_flag = true;
// Benchmark algorithm
if (strcmp(argv[2], "auto") == 0) // This compares what the pointers point to
{
std::vector<int> data_size;
int cur_size;
for (int i = 4; i < 22; i++)
{
cur_size = 2 * pow(r, i);
tie(source_string, pattern) = gen_random(cur_size, cur_size / 10);
data.emplace_back(source_string, pattern);
}
}
}
else {
tie(source_string, pattern) = get_input_data_from_user();
data.emplace_back(source_string, pattern);
}
for (auto&& tuple: data)
{
std::tie(source_string, pattern ) = tuple;
tie(elapsed_time, answers) = run_benchmark(algorithm_number, source_string, pattern);
if (benchmark_flag){
csv.newRow() << algorithm_name << source_string.length() << elapsed_time;
}
else{
std::cout << algorithm_name << "finished work with: "<< elapsed_time << " mcs" << std::endl;
csv.newRow() << algorithm_name << source_string.length() << elapsed_time;
for (auto answer : answers)
std::cout << algorithm_name << "found match with start index: " << answer << std::endl;
}
}
csv.writeToFile("/home/alexander/CLionProjects/SubstringSearch/statistic.csv");
std::cout << algorithm_name << "finished work and csv with statistic was dumped";
return 0;
}