]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/performance/fiber/overhead_detach.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / fiber / performance / fiber / overhead_detach.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
11 #include <boost/cstdint.hpp>
12 #include <boost/fiber/all.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 CREATE(z, n, _) \
22 boost::fibers::fiber BOOST_PP_CAT(f,n) (worker);
23
24 #define DETACH(z, n, _) \
25 BOOST_PP_CAT(f,n) .detach();
26
27 void worker() {}
28
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, DETACH, _);
34 duration_type result = clock_type::now() - start;
35 result -= overhead;
36 result /= JOBS; // joined fibers
37 return result;
38 }
39
40 int main( int argc, char * argv[]) {
41 try {
42 duration_type overhead = overhead_clock();
43 boost::uint64_t res = measure( overhead).count();
44 std::cout << "average of " << res << " nano seconds" << std::endl;
45 return EXIT_SUCCESS;
46 } catch ( std::exception const& e) {
47 std::cerr << "exception: " << e.what() << std::endl;
48 } catch (...) {
49 std::cerr << "unhandled exception" << std::endl;
50 }
51 return EXIT_FAILURE;
52 }