-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval_fft_matching.cpp
More file actions
90 lines (75 loc) · 3.12 KB
/
eval_fft_matching.cpp
File metadata and controls
90 lines (75 loc) · 3.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
#include <iostream>
#include <fstream>
#include <vector>
#include <complex>
#include <math.h>
#include <string.h>
#include <random>
#include <chrono>
#include <map>
#include "fft.hpp"
// #define TO_STRING(VariableName) # VariableName
using namespace std;
string GetFilename(string s, int n, int m) {
string filename = s;
filename += to_string(n);
filename += "_";
filename += to_string(m);
return filename;
}
vector<int> ToIntVector(string s) {
int n = s.length();
vector<int> ans(n);
for (int i = 0; i < n; ++i)
ans[i] = (int)(s[i] - 'a');
return ans;
}
// template<class T>
using matching_function = vector<size_t> (*)(size_t, const vector<int> &, const vector<int> &, fft_function);
// template<class T>
void EvalMathing(string input_filename, string output_filename, size_t alphabet_size, int N_, int N, fft_function Fft, matching_function Matching) {
for (int n = N_; n <= N; n *= 10) {
for (int m = 1; m <= n; m *= 10) {
string input_filename2 = GetFilename(input_filename, n, m);
string output_filename2 = GetFilename(output_filename, n, m);
ifstream ifs(input_filename2);
ofstream ofs(output_filename2);
if (!ifs) {
cout << "cannot open " << input_filename2 << endl;
exit(1);
}
if (!ofs) {
cout << "cannot open" << output_filename2 << endl;
exit(1);
}
ofs << "n: " << n << "m: " << m << endl << flush;
string s, t;
ifs >> n >> m;
ifs >> s >> t;
auto a = ToIntVector(s);
auto b = ToIntVector(t);
auto start = std::chrono::system_clock::now();
auto locs = GetMatchingLocations(26, a, b, RecursiveFft);
auto end = std::chrono::system_clock::now(); // 計測終了時刻を保存
auto dur = end - start; // 要した時間を計算
auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();
// 要した時間をミリ秒(1/1000秒)に変換して表示
ofs << msec << " milli sec \n" << flush;
ifs.close();
ofs.close();
}
}
return;
}
int main(int argc, char *argv[]) {
int N = atoi(argv[1]);
string output_filename = "fft_matching_time/";
string input_filename = "samples/sample_";
EvalMathing(input_filename, output_filename+"recursive/not_fast/", 26, 1000000, N, RecursiveFft, GetMatchingLocations);
EvalMathing(input_filename, output_filename+"recursive/fast/", 26, 10, N, RecursiveFft, GetMatchingLocationsFast);
EvalMathing(input_filename, output_filename+"cooley_tukey/not_fast/", 26, 10, N, CooleyTukeyFft, GetMatchingLocations);
EvalMathing(input_filename, output_filename+"cooley_tukey/fast/", 26, 10, N, CooleyTukeyFft, GetMatchingLocationsFast);
EvalMathing(input_filename, output_filename+"plain/not_fast/", 26, 10, N, PlainDft, GetMatchingLocations);
EvalMathing(input_filename, output_filename+"plain/fast/", 26, 10, N, PlainDft, GetMatchingLocationsFast);
return 0;
}