blob: b19b161ac70b5e29a54755e3e765cad8ef52a5b3 (
plain)
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
|
/*
* Copyright Andrey Semashev 2007 - 2015.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
/*!
* \file dump.cpp
* \author Andrey Semashev
* \date 05.05.2013
*
* \brief This code measures performance dumping binary data
*/
#include <cstdlib>
#include <iomanip>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <boost/cstdint.hpp>
#include <boost/date_time/microsec_time_clock.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/log/utility/formatting_ostream.hpp>
#include <boost/log/utility/manipulators/dump.hpp>
namespace logging = boost::log;
const unsigned int base_loop_count = 10000;
void test(std::size_t block_size)
{
std::cout << "Block size: " << block_size << " bytes.";
std::vector< boost::uint8_t > data;
data.resize(block_size);
std::generate_n(data.begin(), block_size, &std::rand);
std::string str;
logging::formatting_ostream strm(str);
const boost::uint8_t* const p = &data[0];
boost::uint64_t data_processed = 0, duration = 0;
boost::posix_time::ptime start, end;
start = boost::date_time::microsec_clock< boost::posix_time::ptime >::universal_time();
do
{
for (unsigned int i = 0; i < base_loop_count; ++i)
{
strm << logging::dump(p, block_size);
str.clear();
}
end = boost::date_time::microsec_clock< boost::posix_time::ptime >::universal_time();
data_processed += base_loop_count * block_size;
duration = (end - start).total_microseconds();
}
while (duration < 2000000);
std::cout << " Test duration: " << duration << " us ("
<< std::fixed << std::setprecision(3) << static_cast< double >(data_processed) / (static_cast< double >(duration) * (1048576.0 / 1000000.0))
<< " MiB per second)" << std::endl;
}
int main(int argc, char* argv[])
{
test(32);
test(128);
test(1024);
test(16384);
test(1048576);
return 0;
}
|