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