]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/fiber/performance/fiber/scale_join.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / fiber / performance / fiber / scale_join.cpp
CommitLineData
7c673cae
FG
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#define CREATE(z, n, _) \
18 boost::fibers::fiber BOOST_PP_CAT(f,n) (worker);
19#define JOIN(z, n, _) \
20 BOOST_PP_CAT(f,n) .join();
21
22void worker() {}
23
24duration_type measure10( duration_type overhead) {
25 boost::fibers::fiber( worker).join();
26 BOOST_PP_REPEAT_FROM_TO(1, 10, CREATE, _);
27 time_point_type start( clock_type::now() );
28 BOOST_PP_REPEAT_FROM_TO(1, 10, JOIN, _);
29 duration_type total = clock_type::now() - start;
30 total -= overhead_clock(); // overhead of measurement
31 total /= 10; // loops
32 return total;
33}
34
35duration_type measure50( duration_type overhead) {
36 boost::fibers::fiber( worker).join();
37 BOOST_PP_REPEAT_FROM_TO(1, 50, CREATE, _);
38 time_point_type start( clock_type::now() );
39 BOOST_PP_REPEAT_FROM_TO(1, 50, JOIN, _);
40 duration_type total = clock_type::now() - start;
41 total -= overhead_clock(); // overhead of measurement
42 total /= 50; // loops
43 return total;
44}
45
46duration_type measure100( duration_type overhead) {
47 boost::fibers::fiber( worker).join();
48 BOOST_PP_REPEAT_FROM_TO(1, 100, CREATE, _);
49 time_point_type start( clock_type::now() );
50 BOOST_PP_REPEAT_FROM_TO(1, 100, JOIN, _);
51 duration_type total = clock_type::now() - start;
52 total -= overhead_clock(); // overhead of measurement
53 total /= 100; // loops
54 return total;
55}
56
57duration_type measure500( duration_type overhead) {
58 boost::fibers::fiber( worker).join();
59#include "fiber_create_500.ipp"
60 time_point_type start( clock_type::now() );
61#include "fiber_join_500.ipp"
62 duration_type total = clock_type::now() - start;
63 total -= overhead_clock(); // overhead of measurement
64 total /= 500; // loops
65 return total;
66}
67
68duration_type measure1000( duration_type overhead) {
69 boost::fibers::fiber( worker).join();
70#include "fiber_create_1000.ipp"
71 time_point_type start( clock_type::now() );
72#include "fiber_join_1000.ipp"
73 duration_type total = clock_type::now() - start;
74 total -= overhead_clock(); // overhead of measurement
75 total /= 1000; // loops
76 return total;
77}
78
79duration_type measure5000( duration_type overhead) {
80 boost::fibers::fiber( worker).join();
81#include "fiber_create_5000.ipp"
82 time_point_type start( clock_type::now() );
83#include "fiber_join_5000.ipp"
84 duration_type total = clock_type::now() - start;
85 total -= overhead_clock(); // overhead of measurement
86 total /= 5000; // loops
87 return total;
88}
89
90duration_type measure10000( duration_type overhead) {
91 boost::fibers::fiber( worker).join();
92#include "fiber_create_10000.ipp"
93 time_point_type start( clock_type::now() );
94#include "fiber_join_10000.ipp"
95 duration_type total = clock_type::now() - start;
96 total -= overhead_clock(); // overhead of measurement
97 total /= 10000; // loops
98 return total;
99}
100
101int main( int argc, char * argv[]) {
102 try {
103 duration_type overhead = overhead_clock();
104 boost::uint64_t res = measure10( overhead).count();
105 std::cout << "10 jobs: average of " << res << " nano seconds" << std::endl;
106 res = measure50( overhead).count();
107 std::cout << "50 jobs: average of " << res << " nano seconds" << std::endl;
108 res = measure100( overhead).count();
109 std::cout << "100 jobs: average of " << res << " nano seconds" << std::endl;
110 res = measure500( overhead).count();
111 std::cout << "500 jobs: average of " << res << " nano seconds" << std::endl;
112 res = measure1000( overhead).count();
113 std::cout << "1000 jobs: average of " << res << " nano seconds" << std::endl;
114 res = measure5000( overhead).count();
115 std::cout << "5000 jobs: average of " << res << " nano seconds" << std::endl;
116 res = measure10000( overhead).count();
117 std::cout << "10000 jobs: average of " << res << " nano seconds" << std::endl;
118 return EXIT_SUCCESS;
119 } catch ( std::exception const& e) {
120 std::cerr << "exception: " << e.what() << std::endl;
121 } catch (...) {
122 std::cerr << "unhandled exception" << std::endl;
123 }
124 return EXIT_FAILURE;
125}