]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/performance/fiber/overhead_create.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / fiber / performance / fiber / overhead_create.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 JOIN(z, n, _) \
22 { \
23 time_point_type start( clock_type::now() ); \
24 boost::fibers::fiber f( worker); \
25 duration_type total = clock_type::now() - start; \
26 total -= overhead; \
27 result += total; \
28 f.join(); \
29 }
30
31 void worker() {}
32
33 duration_type measure( duration_type overhead) {
34 boost::fibers::fiber( worker).join();
35 duration_type result = duration_type::zero();
36 BOOST_PP_REPEAT_FROM_TO(1, JOBS, JOIN, _)
37 result /= JOBS; // loops
38 return result;
39 }
40
41 int main( int argc, char * argv[]) {
42 try {
43 duration_type overhead = overhead_clock();
44 boost::uint64_t res = measure( overhead).count();
45 std::cout << "average of " << res << " nano seconds" << std::endl;
46 return EXIT_SUCCESS;
47 } catch ( std::exception const& e) {
48 std::cerr << "exception: " << e.what() << std::endl;
49 } catch (...) {
50 std::cerr << "unhandled exception" << std::endl;
51 }
52 return EXIT_FAILURE;
53 }