]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/log/test/performance/dump.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / log / test / performance / dump.cpp
1 /*
2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
6 */
7 /*!
8 * \file dump.cpp
9 * \author Andrey Semashev
10 * \date 05.05.2013
11 *
12 * \brief This code measures performance dumping binary data
13 */
14
15 #include <cstdlib>
16 #include <iomanip>
17 #include <string>
18 #include <vector>
19 #include <iostream>
20 #include <algorithm>
21
22 #include <boost/cstdint.hpp>
23 #include <boost/date_time/microsec_time_clock.hpp>
24 #include <boost/date_time/posix_time/posix_time_types.hpp>
25
26 #include <boost/log/utility/formatting_ostream.hpp>
27 #include <boost/log/utility/manipulators/dump.hpp>
28
29 namespace logging = boost::log;
30
31 const unsigned int base_loop_count = 10000;
32
33 void test(std::size_t block_size)
34 {
35 std::cout << "Block size: " << block_size << " bytes.";
36
37 std::vector< boost::uint8_t > data;
38 data.resize(block_size);
39 std::generate_n(data.begin(), block_size, &std::rand);
40
41 std::string str;
42 logging::formatting_ostream strm(str);
43
44 const boost::uint8_t* const p = &data[0];
45
46 boost::uint64_t data_processed = 0, duration = 0;
47 boost::posix_time::ptime start, end;
48 start = boost::date_time::microsec_clock< boost::posix_time::ptime >::universal_time();
49 do
50 {
51 for (unsigned int i = 0; i < base_loop_count; ++i)
52 {
53 strm << logging::dump(p, block_size);
54 str.clear();
55 }
56 end = boost::date_time::microsec_clock< boost::posix_time::ptime >::universal_time();
57 data_processed += base_loop_count * block_size;
58 duration = (end - start).total_microseconds();
59 }
60 while (duration < 2000000);
61
62 std::cout << " Test duration: " << duration << " us ("
63 << std::fixed << std::setprecision(3) << static_cast< double >(data_processed) / (static_cast< double >(duration) * (1048576.0 / 1000000.0))
64 << " MiB per second)" << std::endl;
65 }
66
67 int main(int argc, char* argv[])
68 {
69 test(32);
70 test(128);
71 test(1024);
72 test(16384);
73 test(1048576);
74
75 return 0;
76 }