]>
Commit | Line | Data |
---|---|---|
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 | #ifndef JOBS | |
18 | #define JOBS BOOST_PP_LIMIT_REPEAT | |
19 | #endif | |
20 | ||
21 | #define WAIT(z, n, _) { \ | |
22 | boost::fibers::packaged_task< void() > pt( worker); \ | |
23 | boost::fibers::future< void > f( pt.get_future() ); \ | |
24 | boost::fibers::fiber( std::move( pt) ).detach(); \ | |
25 | time_point_type start( clock_type::now() ); \ | |
26 | f.wait(); \ | |
27 | duration_type total = clock_type::now() - start; \ | |
28 | total -= overhead; \ | |
29 | result += total; \ | |
30 | } | |
31 | ||
32 | void worker() {} | |
33 | ||
34 | duration_type measure( duration_type overhead) { | |
35 | boost::fibers::fiber( worker).join(); | |
36 | duration_type result = duration_type::zero(); | |
37 | BOOST_PP_REPEAT_FROM_TO(1, JOBS, WAIT, _) | |
38 | result /= JOBS; // loops | |
39 | return result; | |
40 | } | |
41 | ||
42 | int main( int argc, char * argv[]) { | |
43 | try { | |
44 | duration_type overhead = overhead_clock(); | |
45 | boost::uint64_t res = measure( overhead).count(); | |
46 | std::cout << "average of " << res << " nano seconds" << std::endl; | |
47 | return EXIT_SUCCESS; | |
48 | } catch ( std::exception const& e) { | |
49 | std::cerr << "exception: " << e.what() << std::endl; | |
50 | } catch (...) { | |
51 | std::cerr << "unhandled exception" << std::endl; | |
52 | } | |
53 | return EXIT_FAILURE; | |
54 | } |