-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest-6.cpp
113 lines (88 loc) · 3.22 KB
/
test-6.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "ConcurrentHashMap.hpp"
#include <chrono>
#define now std::chrono::high_resolution_clock::now
using namespace std;
int main(int argc, char** argv){
if (argc < 3){
cout << endl << "Error en los parametros de entrada. Los parametros correctos son:" << endl;
cout << endl << "./interza <función> <parámetros>" << endl;
cout << "Funciones a utilizar:" << endl;
cout << "count_words_nc -> Verisón no concurrente, toma un archivo." << endl;
cout << "count_words_c -> Versión concurrente: un thread por archivo." << endl;
cout << "count_words_ct -> Versión concurrente: no pueden haber threads sin trabajar." << endl;
cout << "maximum -> Versión concurrente." << endl;
cout << "maximum_cw_c -> Versión concurrente con count_words_c." << endl;
cout << "maximum_cw_ct -> Versión concurrente con count_words_ct." << endl;
cout << endl << "Los parámetro serán los de la función elegida." << endl;
return -1;
}
//inicializo las variables para medir el tiempo
chrono::high_resolution_clock::time_point t1;
chrono::high_resolution_clock::time_point t2;
chrono::duration<double> time_span;
string funcion = argv[1];
if(funcion != "count_words_c"){
if (argv[2] == "1"){
cout << "tiempo" << "," << "threads" << endl;
}
}
if(funcion == "count_words_nc"){
string arch = argv[2];
t1 = now();
count_words(arch);
t2 = now();
} else if(funcion == "count_words_c"){
list<string> archs;
for (int i = 2; i < argc; ++i){
archs.push_back(argv[i]);
}
t1 = now();
count_words(archs);
t2 = now();
} else if(funcion == "count_words_ct"){
int n = atoi(argv[2]);
list<string> archs;
for (int i = 3; i < argc; ++i){
archs.push_back(argv[i]);
}
t1 = now();
count_words(n, archs);
t2 = now();
} else if(funcion == "maximum"){
int p_archivos = atoi(argv[2]);
int p_maximos = atoi(argv[3]);
list<string> archs;
for (int i = 4; i < argc; ++i){
archs.push_back(argv[i]);
}
t1 = now();
maximum(p_archivos, p_maximos, archs);
t2 = now();
} else if(funcion == "maximum_cw_c"){
int p_archivos = atoi(argv[2]);
int p_maximos = atoi(argv[3]);
list<string> archs;
for (int i = 4; i < argc; ++i){
archs.push_back(argv[i]);
}
t1 = now();
maximum2(p_archivos, p_maximos, archs);
t2 = now();
} else if(funcion == "maximum_cw_ct"){
int p_archivos = atoi(argv[2]);
int p_maximos = atoi(argv[3]);
list<string> archs;
for (int i = 4; i < argc; ++i){
archs.push_back(argv[i]);
}
t1 = now();
maximum3(p_archivos, p_maximos, archs);
t2 = now();
}
time_span = std::chrono::duration_cast<std::chrono::duration<double> >(t2-t1);
cout << time_span.count();
if(funcion == "count_words_c"){cout << "," << 16;}//nos metimos con 16 corpus en los experimentos
else { cout << "," << argv[2];}
cout << endl;
return 0;
}