]>
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 | #include <string> | |
11 | #include <thread> | |
12 | ||
13 | #include <boost/cstdint.hpp> | |
14 | #include <boost/preprocessor.hpp> | |
15 | #include <boost/program_options.hpp> | |
16 | ||
17 | #include "../clock.hpp" | |
18 | ||
19 | #ifndef JOBS | |
20 | #define JOBS BOOST_PP_LIMIT_REPEAT | |
21 | #endif | |
22 | ||
23 | #define DETACH(z, n, _) \ | |
24 | { \ | |
25 | std::thread t( worker); \ | |
26 | time_point_type start( clock_type::now() ); \ | |
27 | t.detach(); \ | |
28 | duration_type total = clock_type::now() - start; \ | |
29 | total -= overhead; \ | |
30 | result += total; \ | |
31 | } | |
32 | ||
33 | void worker() {} | |
34 | ||
35 | duration_type measure( duration_type overhead) | |
36 | { | |
37 | std::thread( worker).join(); | |
38 | ||
39 | duration_type result = duration_type::zero(); | |
40 | ||
41 | BOOST_PP_REPEAT_FROM_TO(1, JOBS, DETACH, _) | |
42 | ||
43 | result /= JOBS; // loops | |
44 | ||
45 | return result; | |
46 | } | |
47 | ||
48 | int main( int argc, char * argv[]) | |
49 | { | |
50 | try | |
51 | { | |
52 | duration_type overhead = overhead_clock(); | |
53 | boost::uint64_t res = measure( overhead).count(); | |
54 | std::cout << "average of " << res << " nano seconds" << std::endl; | |
55 | ||
56 | return EXIT_SUCCESS; | |
57 | } | |
58 | catch ( std::exception const& e) | |
59 | { std::cerr << "exception: " << e.what() << std::endl; } | |
60 | catch (...) | |
61 | { std::cerr << "unhandled exception" << std::endl; } | |
62 | return EXIT_FAILURE; | |
63 | } |