]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/performance/thread/overhead_future.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / fiber / performance / thread / overhead_future.cpp
1
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)
6
7 #include <cstdlib>
8 #include <future>
9 #include <iostream>
10 #include <stdexcept>
11 #include <thread>
12
13 #include <boost/cstdint.hpp>
14 #include <boost/preprocessor.hpp>
15
16 #include "../clock.hpp"
17
18 #ifndef JOBS
19 #define JOBS BOOST_PP_LIMIT_REPEAT
20 #endif
21
22 #define WAIT(z, n, _) \
23 { \
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() ); \
28 f.wait(); \
29 duration_type total = clock_type::now() - start; \
30 total -= overhead; \
31 result += total; \
32 }
33
34 void worker() {}
35
36 duration_type measure( duration_type overhead)
37 {
38 std::thread( worker).join();
39
40 duration_type result = duration_type::zero();
41
42 BOOST_PP_REPEAT_FROM_TO(1, JOBS, WAIT, _)
43
44 result /= JOBS; // loops
45
46 return result;
47 }
48
49 int main( int argc, char * argv[])
50 {
51 try
52 {
53 duration_type overhead = overhead_clock();
54 boost::uint64_t res = measure( overhead).count();
55 std::cout << "average of " << res << " nano seconds" << std::endl;
56
57 return EXIT_SUCCESS;
58 }
59 catch ( std::exception const& e)
60 { std::cerr << "exception: " << e.what() << std::endl; }
61 catch (...)
62 { std::cerr << "unhandled exception" << std::endl; }
63 return EXIT_FAILURE;
64 }