]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/performance/fiber/scale_join.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)
11 #include <boost/cstdint.hpp>
12 #include <boost/fiber/all.hpp>
13 #include <boost/preprocessor.hpp>
15 #include "../clock.hpp"
17 #define CREATE(z, n, _) \
18 boost::fibers::fiber BOOST_PP_CAT(f,n) (worker);
19 #define JOIN(z, n, _) \
20 BOOST_PP_CAT(f,n) .join();
24 duration_type
measure10( duration_type overhead
) {
25 boost::fibers::fiber( worker
).join();
26 BOOST_PP_REPEAT_FROM_TO(1, 10, CREATE
, _
);
27 time_point_type
start( clock_type::now() );
28 BOOST_PP_REPEAT_FROM_TO(1, 10, JOIN
, _
);
29 duration_type total
= clock_type::now() - start
;
30 total
-= overhead_clock(); // overhead of measurement
35 duration_type
measure50( duration_type overhead
) {
36 boost::fibers::fiber( worker
).join();
37 BOOST_PP_REPEAT_FROM_TO(1, 50, CREATE
, _
);
38 time_point_type
start( clock_type::now() );
39 BOOST_PP_REPEAT_FROM_TO(1, 50, JOIN
, _
);
40 duration_type total
= clock_type::now() - start
;
41 total
-= overhead_clock(); // overhead of measurement
46 duration_type
measure100( duration_type overhead
) {
47 boost::fibers::fiber( worker
).join();
48 BOOST_PP_REPEAT_FROM_TO(1, 100, CREATE
, _
);
49 time_point_type
start( clock_type::now() );
50 BOOST_PP_REPEAT_FROM_TO(1, 100, JOIN
, _
);
51 duration_type total
= clock_type::now() - start
;
52 total
-= overhead_clock(); // overhead of measurement
53 total
/= 100; // loops
57 duration_type
measure500( duration_type overhead
) {
58 boost::fibers::fiber( worker
).join();
59 #include "fiber_create_500.ipp"
60 time_point_type
start( clock_type::now() );
61 #include "fiber_join_500.ipp"
62 duration_type total
= clock_type::now() - start
;
63 total
-= overhead_clock(); // overhead of measurement
64 total
/= 500; // loops
68 duration_type
measure1000( duration_type overhead
) {
69 boost::fibers::fiber( worker
).join();
70 #include "fiber_create_1000.ipp"
71 time_point_type
start( clock_type::now() );
72 #include "fiber_join_1000.ipp"
73 duration_type total
= clock_type::now() - start
;
74 total
-= overhead_clock(); // overhead of measurement
75 total
/= 1000; // loops
79 duration_type
measure5000( duration_type overhead
) {
80 boost::fibers::fiber( worker
).join();
81 #include "fiber_create_5000.ipp"
82 time_point_type
start( clock_type::now() );
83 #include "fiber_join_5000.ipp"
84 duration_type total
= clock_type::now() - start
;
85 total
-= overhead_clock(); // overhead of measurement
86 total
/= 5000; // loops
90 duration_type
measure10000( duration_type overhead
) {
91 boost::fibers::fiber( worker
).join();
92 #include "fiber_create_10000.ipp"
93 time_point_type
start( clock_type::now() );
94 #include "fiber_join_10000.ipp"
95 duration_type total
= clock_type::now() - start
;
96 total
-= overhead_clock(); // overhead of measurement
97 total
/= 10000; // loops
101 int main( int argc
, char * argv
[]) {
103 duration_type overhead
= overhead_clock();
104 boost::uint64_t res
= measure10( overhead
).count();
105 std::cout
<< "10 jobs: average of " << res
<< " nano seconds" << std::endl
;
106 res
= measure50( overhead
).count();
107 std::cout
<< "50 jobs: average of " << res
<< " nano seconds" << std::endl
;
108 res
= measure100( overhead
).count();
109 std::cout
<< "100 jobs: average of " << res
<< " nano seconds" << std::endl
;
110 res
= measure500( overhead
).count();
111 std::cout
<< "500 jobs: average of " << res
<< " nano seconds" << std::endl
;
112 res
= measure1000( overhead
).count();
113 std::cout
<< "1000 jobs: average of " << res
<< " nano seconds" << std::endl
;
114 res
= measure5000( overhead
).count();
115 std::cout
<< "5000 jobs: average of " << res
<< " nano seconds" << std::endl
;
116 res
= measure10000( overhead
).count();
117 std::cout
<< "10000 jobs: average of " << res
<< " nano seconds" << std::endl
;
119 } catch ( std::exception
const& e
) {
120 std::cerr
<< "exception: " << e
.what() << std::endl
;
122 std::cerr
<< "unhandled exception" << std::endl
;