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