]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/context/performance/ec_v2/performance.cpp
2 // Copyright Oliver Kowalke 2009.
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)
12 #include <boost/context/all.hpp>
13 #include <boost/cstdint.hpp>
14 #include <boost/program_options.hpp>
16 #include "../bind_processor.hpp"
17 #include "../clock.hpp"
18 #include "../cycle.hpp"
20 boost::uint64_t jobs
= 1000;
22 static boost::context::execution_context
< void > foo( boost::context::execution_context
< void > ctx
) {
28 duration_type
measure_time() {
30 boost::context::execution_context
< void > ctx( foo
);
33 time_point_type
start( clock_type::now() );
34 for ( std::size_t i
= 0; i
< jobs
; ++i
) {
37 duration_type total
= clock_type::now() - start
;
38 total
-= overhead_clock(); // overhead of measurement
39 total
/= jobs
; // loops
40 total
/= 2; // 2x jump_fcontext
45 duration_type
measure_time_() {
47 boost::context::fixedsize_stack alloc
;
48 boost::context::execution_context
< void > ctx( std::allocator_arg
, alloc
, foo
);
51 time_point_type
start( clock_type::now() );
52 for ( std::size_t i
= 0; i
< jobs
; ++i
) {
53 ctx
= ctx( boost::context::exec_ontop_arg
,
54 [](boost::context::execution_context
< void > ctx
){
55 return std::move( ctx
);
58 duration_type total
= clock_type::now() - start
;
59 total
-= overhead_clock(); // overhead of measurement
60 total
/= jobs
; // loops
61 total
/= 2; // 2x jump_fcontext
66 #ifdef BOOST_CONTEXT_CYCLE
67 cycle_type
measure_cycles() {
69 boost::context::fixedsize_stack alloc
;
70 boost::context::execution_context
< void > ctx( std::allocator_arg
, alloc
, foo
);
73 cycle_type
start( cycles() );
74 for ( std::size_t i
= 0; i
< jobs
; ++i
) {
77 cycle_type total
= cycles() - start
;
78 total
-= overhead_cycle(); // overhead of measurement
79 total
/= jobs
; // loops
80 total
/= 2; // 2x jump_fcontext
85 cycle_type
measure_cycles_() {
87 boost::context::fixedsize_stack alloc
;
88 boost::context::execution_context
< void > ctx( std::allocator_arg
, alloc
, foo
);
91 cycle_type
start( cycles() );
92 for ( std::size_t i
= 0; i
< jobs
; ++i
) {
93 ctx
= ctx( boost::context::exec_ontop_arg
,
94 [](boost::context::execution_context
< void > ctx
){
95 return std::move( ctx
);
98 cycle_type total
= cycles() - start
;
99 total
-= overhead_cycle(); // overhead of measurement
100 total
/= jobs
; // loops
101 total
/= 2; // 2x jump_fcontext
107 int main( int argc
, char * argv
[]) {
109 bind_to_processor( 0);
111 boost::program_options::options_description
desc("allowed options");
113 ("help", "help message")
114 ("jobs,j", boost::program_options::value
< boost::uint64_t >( & jobs
), "jobs to run");
116 boost::program_options::variables_map vm
;
117 boost::program_options::store(
118 boost::program_options::parse_command_line(
123 boost::program_options::notify( vm
);
125 if ( vm
.count("help") ) {
126 std::cout
<< desc
<< std::endl
;
130 boost::uint64_t res
= measure_time().count();
131 std::cout
<< "execution_context: average of " << res
<< " nano seconds" << std::endl
;
132 res
= measure_time_().count();
133 std::cout
<< "execution_context: average of (ontop) " << res
<< " nano seconds" << std::endl
;
134 #ifdef BOOST_CONTEXT_CYCLE
135 res
= measure_cycles();
136 std::cout
<< "execution_context: average of " << res
<< " cpu cycles" << std::endl
;
137 res
= measure_cycles_();
138 std::cout
<< "execution_context: average of (ontop) " << res
<< " cpu cycles" << std::endl
;
142 } catch ( std::exception
const& e
) {
143 std::cerr
<< "exception: " << e
.what() << std::endl
;
145 std::cerr
<< "unhandled exception" << std::endl
;