-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
49 lines (41 loc) · 1.91 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
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#include "ahocorasick.h"
#include "karprabin.h"
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ifstream in("english.50MB");
stringstream buffer;
buffer << in.rdbuf();
string text = buffer.str();
vector<string> matching;
srand(time(NULL));
for (int i = 0; i < 1000; i++) {
ll b = rand() % text.length()-1000;
matching.push_back(text.substr(b, 1000));
}
ll ms,ms2;
ms = chrono::duration_cast< chrono::milliseconds >(chrono::system_clock::now().time_since_epoch()).count();
preprocess_ac(matching);
ms2 = chrono::duration_cast< chrono::milliseconds >(chrono::system_clock::now().time_since_epoch()).count();
cout << "Preprocessing done for Aho-Corasick" << endl;
cout << "It took " << ms2 - ms << " milliseconds." << endl;
ms = chrono::duration_cast< chrono::milliseconds >(chrono::system_clock::now().time_since_epoch()).count();
vector<pair<ll,ll>> op = findPattern(text);
ms2 = chrono::duration_cast< chrono::milliseconds >(chrono::system_clock::now().time_since_epoch()).count();
cout << "Search phase done for Aho-Corasick" << endl;
cout << "It took " << ms2 - ms << " milliseconds." << endl;
ms = chrono::duration_cast< chrono::milliseconds >(chrono::system_clock::now().time_since_epoch()).count();
preprocess_KR(matching, text);
ms2 = chrono::duration_cast< chrono::milliseconds >(chrono::system_clock::now().time_since_epoch()).count();
cout << "Preprocessing done for Karp-Rabin." << endl;
cout << "It took " << ms2 - ms << " milliseconds." << endl;
ms = chrono::duration_cast< chrono::milliseconds >(chrono::system_clock::now().time_since_epoch()).count();
findPatterns(text, matching);
ms2 = chrono::duration_cast< chrono::milliseconds >(chrono::system_clock::now().time_since_epoch()).count();
cout << "Search phase done for Karp-Rabin." << endl;
cout << "It took " << ms2 - ms << " milliseconds." << endl;
}