]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/performance/thread/overhead_future.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)
13 #include <boost/cstdint.hpp>
14 #include <boost/preprocessor.hpp>
16 #include "../clock.hpp"
19 #define JOBS BOOST_PP_LIMIT_REPEAT
22 #define WAIT(z, n, _) \
24 std::packaged_task< void() > pt( worker); \
25 std::future< void > f( pt.get_future() ); \
26 std::thread( std::move( pt) ).detach(); \
27 time_point_type start( clock_type::now() ); \
29 duration_type total = clock_type::now() - start; \
36 duration_type
measure( duration_type overhead
)
38 std::thread( worker
).join();
40 duration_type result
= duration_type::zero();
42 BOOST_PP_REPEAT_FROM_TO(1, JOBS
, WAIT
, _
)
44 result
/= JOBS
; // loops
49 int main( int argc
, char * argv
[])
53 duration_type overhead
= overhead_clock();
54 boost::uint64_t res
= measure( overhead
).count();
55 std::cout
<< "average of " << res
<< " nano seconds" << std::endl
;
59 catch ( std::exception
const& e
)
60 { std::cerr
<< "exception: " << e
.what() << std::endl
; }
62 { std::cerr
<< "unhandled exception" << std::endl
; }