-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBenchmark.cpp
123 lines (109 loc) · 2.73 KB
/
Benchmark.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
114
115
116
117
118
119
120
121
122
123
/***********************************************************
> File Name: Benchmark.cpp
> Author: Weidong, ZHANG
> Mail: [email protected]
> Created Time: Sat 07 Mar 2015 07:07:58 PM PST
**********************************************************/
#include "Benchmark.h"
using namespace benchmark;
namespace benchmark {
///////////Defination of Benchmark//////////
Benchmark::Benchmark()
{
_cluster = make_shared<Cluster>();
_nfi = make_shared<NETWORK_INTERFACE>(*_cluster);
_tm = make_shared<TimeMeasure>();
}
Benchmark::~Benchmark()
{
}
///////////Defination of ConnectionTime//////////
ConnectionTime::ConnectionTime() : Benchmark()
{
}
void ConnectionTime::test()
{
_tm->start();
if (_nfi->connect() == -1)
{
std::cout << "No Resource Founded ... ";
return;
}
_tm->stop();
cout << "Connect consumption:" << _tm->getRuntime() << "s" << endl;
}
///////////Defination of TransFileTime///////////
TransFileTime::TransFileTime() : Benchmark()
{
if (_nfi->connect() == -1)
std::cout << "Connect failed...\n";
}
void TransFileTime::test()
{
testTransDir("testDir");
}
void TransFileTime::testTransFile(string filename)
{
_tm->start();
_nfi->pushFile(filename);
_tm->stop();
cout << "File:" << setw(12)<< left << filename << " size:" <<
setw(8) << LocalFileSystem::getFileSize(filename) <<
" Elapse:" << setw(8) << _tm->getRuntime() << "s" << endl;
}
void TransFileTime::testTransDir(string dirname)
{
vector<string> filenames = LocalFileSystem::listDirFiles(dirname);
auto iter = filenames.begin();
for (; iter != filenames.end(); iter++)
testTransFile("testDir/" + *iter);
}
///////////Defination of NetworkUseRate//////////
NetworkUseRate::NetworkUseRate() : Benchmark()
{ }
void NetworkUseRate::test()
{
cout << "Network Usage Rate:0.0%" << endl;
}
///////////Defination of TimeMeasure/////////////
TimeMeasure::TimeMeasure()
{ }
struct timeval TimeMeasure::start()
{
gettimeofday(&begin_time, NULL);
return begin_time;
}
struct timeval TimeMeasure::stop()
{
gettimeofday(&end_time, NULL);
return end_time;
}
double TimeMeasure::getRuntime()
{
long seconds = end_time.tv_sec - begin_time.tv_sec;
long useconds = end_time.tv_usec - begin_time.tv_usec;
return double(seconds * 1000 * 1000 + useconds) /
CLOCKS_PER_SEC;
}
struct timeval TimeMeasure::getBegintime()
{
return begin_time;
}
struct timeval TimeMeasure::getEndtime()
{
return end_time;
}
} // end of namespace benchmark
int main()
{
// Connection time test
ConnectionTime ct;
ct.test();
// Transfer time test
TransFileTime tft;
tft.test();
// Network usage rate test
NetworkUseRate nur;
nur.test();
return 0;
}