2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-01-29 19:42:08 +00:00
Files
fiber/performance/thread/overhead_detach.cpp
2014-07-31 18:04:25 +02:00

61 lines
1.5 KiB
C++

// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <string>
#include <boost/chrono.hpp>
#include <boost/cstdint.hpp>
#include <boost/preprocessor.hpp>
#include <boost/program_options.hpp>
#include <boost/thread.hpp>
#include "../clock.hpp"
#ifndef JOBS
#define JOBS BOOST_PP_LIMIT_REPEAT
#endif
#define DETACH(z, n, _) \
boost::thread( worker).detach();
void worker() {}
duration_type measure( duration_type overhead)
{
boost::thread( worker).join();
time_point_type start( clock_type::now() );
BOOST_PP_REPEAT_FROM_TO(1, JOBS, DETACH, _)
duration_type total = clock_type::now() - start;
total -= overhead_clock(); // overhead of measurement
total /= JOBS; // loops
return total;
}
int main( int argc, char * argv[])
{
try
{
duration_type overhead = overhead_clock();
std::cout << "overhead " << overhead.count() << " nano seconds" << std::endl;
boost::uint64_t res = measure( overhead).count();
std::cout << "average of " << res << " nano seconds" << std::endl;
return EXIT_SUCCESS;
}
catch ( std::exception const& e)
{ std::cerr << "exception: " << e.what() << std::endl; }
catch (...)
{ std::cerr << "unhandled exception" << std::endl; }
return EXIT_FAILURE;
}