]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/log/test/performance/dump.cpp
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)
9 * \author Andrey Semashev
12 * \brief This code measures performance dumping binary data
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>
26 #include <boost/log/utility/formatting_ostream.hpp>
27 #include <boost/log/utility/manipulators/dump.hpp>
29 namespace logging
= boost::log
;
31 const unsigned int base_loop_count
= 10000;
33 void test(std::size_t block_size
)
35 std::cout
<< "Block size: " << block_size
<< " bytes.";
37 std::vector
< boost::uint8_t > data
;
38 data
.resize(block_size
);
39 std::generate_n(data
.begin(), block_size
, &std::rand
);
42 logging::formatting_ostream
strm(str
);
44 const boost::uint8_t* const p
= &data
[0];
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();
51 for (unsigned int i
= 0; i
< base_loop_count
; ++i
)
53 strm
<< logging::dump(p
, block_size
);
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();
60 while (duration
< 2000000);
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
;
67 int main(int argc
, char* argv
[])