-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
53 lines (43 loc) · 896 Bytes
/
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
#include "SpaceSaving.h"
#include <ctime>
#include <fstream>
int main(int argc, char const *argv[])
{
if (argc != 3)
{
cerr << "Error: Expected 3 Arguments" << endl;
exit(1);
}
vector<string> input;
ifstream ifs;
ifs.open(argv[1]);
if (!ifs)
{
cerr << "Open Failed" << endl;
exit(1);
}
string line;
while (true)
{
getline(ifs, line);
if (!ifs)
{
break;
}
input.push_back(line);
}
int capacity = stoi(argv[2]);
SpaceSaving obj(capacity);
clock_t t;
t = clock();
for (auto &&id : input)
{
obj.spaceSaving(id);
}
t = clock() - t;
double time = ((double)t) / CLOCKS_PER_SEC;
cout << "Running time: " << 1e9 * time/input.size() << " nanoseconds." << "\n";
cout << "\n";
obj.print();
return 0;
}