-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
59 lines (46 loc) · 1.37 KB
/
main.cc
File metadata and controls
59 lines (46 loc) · 1.37 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
#include <sstream>
#include <iostream>
#include <string>
#include <fstream>
#include <chrono>
#include <memory>
#include "compress.h"
int main(int argc, char *argv[]) {
if (
argc != 4 ||
!(std::string(argv[1]) == "compress" || std::string(argv[1]) == "decompress")
) {
std::cout << "Usage: " << argv[0] << " <\"compress\" | \"decompress\"> <algorithm> <file>" << std::endl;
return 1;
}
//std::unique_ptr<Compressor> compressor = std::make_unique<SinglethreadedCompressor>();
std::unique_ptr<Compressor> compressor = std::make_unique<MultithreadedCompressor>();
std::ifstream ifile(argv[3]);
auto start = std::chrono::high_resolution_clock::now();
File output;
if (std::string(argv[1]) == "compress") {
output = compressor->compress(ifile);
} else {
output = compressor->decompress(ifile);
}
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
std::cout
<< "Finished "
<< argv[1]
<< " on file "
<< argv[3]
<< " with algorithm "
<< argv[2]
<< " in "
<< duration.count()
<< std::endl;
std::ofstream ofile;
if (std::string(argv[1]) == "compress") {
ofile.open(std::string(argv[3]) + "-compressed");
} else {
ofile.open(std::string(argv[3]) + "-decompressed");
}
ofile << output.data;
return 0;
}