-
Notifications
You must be signed in to change notification settings - Fork 5
/
mul.cpp
57 lines (38 loc) · 1.12 KB
/
mul.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
#include <iostream>
#include <vector>
#include <ctime>
#include <fstream>
#include "mul_lib.hpp"
using namespace std;
using namespace Mul_lib;
int main() {
vector<long long> first, second;
vector<long long> res;
ifstream ifs{"nums.txt"};
ofstream ofs{"out.txt"};
if (!ifs) {
cerr << "Error: File could not be found\n";
return 1;
}
first = get_number(ifs);
second = get_number(ifs);
auto n = max(first.size(), second.size());
extend_vec(first, n);
extend_vec(second, n);
clock_t t;
t = clock();
res = naive_mul(first, second);
finalize(res);
t = clock() - t;
print_res(res, ofs);
cout << "Naive algorithm took me " << t << " cycles (" << static_cast<float> (t) / CLOCKS_PER_SEC <<
" seconds)\n";
t = clock();
res = karatsuba_mul(first, second);
finalize(res);
t = clock() - t;
print_res(res, ofs);
cout << "Karatsuba algorithm took me " << t << " cycles (" << static_cast<float> (t) / CLOCKS_PER_SEC <<
" seconds)\n";
return 0;
}