-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfft.cpp
58 lines (45 loc) · 1.7 KB
/
fft.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
#include "test_utils.hpp"
#include "numeric/fft.hpp"
template <typename Num = int64_t>
void stress_test_fft_multiply(int V) {
LOOP_FOR_DURATION_OR_RUNS_TRACKED (20s, now, 100'000, runs) {
print_time(now, 20s, "stress fft ({} runs)", runs);
int A = rand_unif<int>(0, 1000);
int B = rand_unif<int>(0, 1000);
auto a = rands_unif<int, Num>(A, -V, V);
auto b = rands_unif<int, Num>(B, -V, V);
auto c = fft::fft_multiply(a, b);
auto d = fft::naive_multiply(a, b);
assert(c == d);
}
}
template <typename Num = int64_t>
void speed_test_fft_multiply(Num V) {
vector<int> As = {6000, 15000, 30000, 50000, 100000, 200000, 300000, 500000, 800000};
vector<int> Bs = {6000, 15000, 30000, 50000, 100000, 200000, 300000, 500000, 800000};
vector<pair<int, int>> inputs;
for (int A : As) {
for (int B : Bs) {
inputs.push_back({A, B});
}
}
const auto runtime = 120'000ms / (As.size() * Bs.size());
map<pair<int, int>, string> table;
for (auto [A, B] : inputs) {
START_ACC(fft);
LOOP_FOR_DURATION_OR_RUNS_TRACKED (runtime, now, 10000, runs) {
print_time(now, runtime, "speed fft A={} B={} ({} runs)", A, B, runs);
auto a = rands_unif<int, Num>(A, -V, V);
auto b = rands_unif<int, Num>(B, -V, V);
ADD_TIME_BLOCK(fft) { fft::fft_multiply(a, b); }
}
table[{A, B}] = FORMAT_EACH(fft, runs);
}
print_time_table(table, "FFT multiply");
}
int main() {
RUN_BLOCK(stress_test_fft_multiply<int>(1000));
RUN_BLOCK(stress_test_fft_multiply<int64_t>(100'000));
RUN_BLOCK(speed_test_fft_multiply<int64_t>(100'000));
return 0;
}