]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/performance/thread/overhead_yield.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/cstdint.hpp>
13 #include <boost/preprocessor.hpp>
15 #include "../clock.hpp"
18 #define JOBS BOOST_PP_LIMIT_REPEAT
21 #define JOIN(z, n, _) \
22 std::thread( worker, overhead, & result).join();
24 void worker( duration_type overhead
, duration_type
* result
)
26 time_point_type
start( clock_type::now() );
27 std::this_thread::yield();
28 duration_type total
= clock_type::now() - start
;
33 duration_type
measure( duration_type overhead
)
35 duration_type result
= duration_type::zero();
37 std::thread( worker
, overhead
, & result
).join();
39 result
= duration_type::zero();
41 BOOST_PP_REPEAT_FROM_TO(1, JOBS
, JOIN
, _
)
43 result
/= JOBS
; // loops
48 int main( int argc
, char * argv
[])
52 duration_type overhead
= overhead_clock();
53 boost::uint64_t res
= measure( overhead
).count();
54 std::cout
<< "average of " << res
<< " nano seconds" << std::endl
;
58 catch ( std::exception
const& e
)
59 { std::cerr
<< "exception: " << e
.what() << std::endl
; }
61 { std::cerr
<< "unhandled exception" << std::endl
; }