]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/fiber/performance/tbb/overhead_join.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / fiber / performance / tbb / 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 <string>
11
12#include <boost/atomic.hpp>
13#include <boost/chrono.hpp>
14#include <boost/cstdint.hpp>
15#include <boost/preprocessor.hpp>
16#include <boost/program_options.hpp>
17
18#include <tbb/task.h>
19#include <tbb/task_scheduler_init.h>
20
21#include "../clock.hpp"
22
23#ifndef JOBS
24#define JOBS BOOST_PP_LIMIT_REPEAT
25#endif
26
27struct worker: public tbb::task
28{
29 tbb::task * execute()
30 { return 0; }
31};
32
33struct spawner : public tbb::task
34{
35 tbb::task * execute()
36 {
37 set_ref_count( static_cast< int >( JOBS + 1) );
38
39 for ( boost::uint64_t i = 0; i < JOBS; ++i)
40 {
41 worker & wrk = *new ( tbb::task::allocate_child() ) worker();
42
43 if ( i == ( JOBS - 1) )
44 spawn_and_wait_for_all( wrk);
45 else
46 spawn( wrk);
47 }
48
49 return 0;
50 }
51};
52
53duration_type measure( duration_type overhead)
54{
55 time_point_type start( clock_type::now() );
56 spawner & spw = *new ( tbb::task::allocate_root() ) spawner();
57 tbb::task::spawn_root_and_wait( spw);
58 duration_type total = clock_type::now() - start;
59 total -= overhead_clock(); // overhead of measurement
60 total /= JOBS; // loops
61
62 return total;
63}
64
65int main( int argc, char * argv[])
66{
67 try
68 {
69 boost::program_options::options_description desc("allowed options");
70 desc.add_options()
71 ("help", "help message");
72
73 boost::program_options::variables_map vm;
74 boost::program_options::store(
75 boost::program_options::parse_command_line(
76 argc,
77 argv,
78 desc),
79 vm);
80 boost::program_options::notify( vm);
81
82 if ( vm.count("help") ) {
83 std::cout << desc << std::endl;
84 return EXIT_SUCCESS;
85 }
86
87 tbb::task_scheduler_init init( 1);
88
89 duration_type overhead = overhead_clock();
90 boost::uint64_t res = measure( overhead).count();
91 std::cout << JOBS << " jobs: average of " << res << " nano seconds" << std::endl;
92
93 return EXIT_SUCCESS;
94 }
95 catch ( std::exception const& e)
96 { std::cerr << "exception: " << e.what() << std::endl; }
97 catch (...)
98 { std::cerr << "unhandled exception" << std::endl; }
99 return EXIT_FAILURE;
100}