-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
68 lines (59 loc) · 1.79 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
#include <iostream>
#include <fstream>
#include <cassert>
#include <chrono>
#include "BigInt.h"
using namespace std;
void generateTest() {
ofstream inp("input.txt");
inp << 20 << endl;
for (int i = 1; i <= 20; i++) {
int numDigit = (i - 1) * 10000 + 3;
for (int j = 1; j <= numDigit; j++) {
inp << (char) (rand() % 10 + '0');
}
inp << " ";
for (int j = 1; j <= numDigit; j++) {
inp << (char) (rand() % 10 + '0');
}
inp << endl;
}
}
// get data from input.txt, print to output.txt
// input.txt is as the form:
// the first line contains one number: numTests
// each of next numTests lines contains 2 integers
// for each test, we will print out the product of those integers on 1 line
void test() {
using namespace std::chrono;
ifstream inp("input.txt");
ofstream out("output.txt");
ofstream timeResult("time.csv");
if (!inp.is_open()) {
cout << "Cannot open file" << endl;
return;
}
int numTest;
inp >> numTest;
for (int i = 1; i <= numTest; i++) {
BigInt a, b;
inp >> a >> b;
// calculate and measure time
auto start = high_resolution_clock::now();
BigInt prodBrute = a.mulBrute(b);
auto stop = high_resolution_clock::now();
auto durationBrute = duration_cast<milliseconds>(stop - start);
start = high_resolution_clock::now();
BigInt prodFFT = a.mulFFT(b);
stop = high_resolution_clock::now();
auto durationFFT = duration_cast<milliseconds>(stop - start);
assert(prodBrute == prodFFT);
out << prodBrute << endl;
timeResult << durationBrute.count() << "," << durationFFT.count() << endl;
}
}
int main() {
// generateTest();
test();
return 0;
}