]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/performance/fiber/overhead_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"
18 #define JOBS BOOST_PP_LIMIT_REPEAT
21 #define CREATE(z, n, _) \
22 boost::fibers::fiber BOOST_PP_CAT(f,n) (worker);
24 #define JOIN(z, n, _) \
25 BOOST_PP_CAT(f,n) .join();
29 duration_type
measure( duration_type overhead
) {
30 boost::fibers::fiber( worker
).join();
31 BOOST_PP_REPEAT_FROM_TO(1, JOBS
, CREATE
, _
)
32 time_point_type
start( clock_type::now() );
33 BOOST_PP_REPEAT_FROM_TO(1, JOBS
, JOIN
, _
);
34 duration_type result
= clock_type::now() - start
;
36 result
/= JOBS
; // joined fibers
40 int main( int argc
, char * argv
[]) {
42 duration_type overhead
= overhead_clock();
43 boost::uint64_t res
= measure( overhead
).count();
44 std::cout
<< "average of " << res
<< " nano seconds" << std::endl
;
46 } catch ( std::exception
const& e
) {
47 std::cerr
<< "exception: " << e
.what() << std::endl
;
49 std::cerr
<< "unhandled exception" << std::endl
;