mirror of
https://github.com/boostorg/fiber.git
synced 2026-01-30 07:52:07 +00:00
79 lines
2.2 KiB
C++
79 lines
2.2 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/program_options.hpp>
|
|
#include <boost/thread.hpp>
|
|
|
|
#include "../bind_processor.hpp"
|
|
#include "../clock.hpp"
|
|
|
|
boost::uint64_t jobs = 1000;
|
|
|
|
void worker() {}
|
|
|
|
duration_type measure( duration_type overhead)
|
|
{
|
|
boost::thread( worker).join();
|
|
|
|
time_point_type start( clock_type::now() );
|
|
for ( std::size_t i = 0; i < jobs; ++i) {
|
|
boost::thread( worker).join();
|
|
}
|
|
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
|
|
{
|
|
bool bind = false;
|
|
boost::program_options::options_description desc("allowed options");
|
|
desc.add_options()
|
|
("help", "help message")
|
|
("bind,b", boost::program_options::value< bool >( & bind), "bind thread to CPU")
|
|
("jobs,j", boost::program_options::value< boost::uint64_t >( & jobs), "jobs to run");
|
|
|
|
boost::program_options::variables_map vm;
|
|
boost::program_options::store(
|
|
boost::program_options::parse_command_line(
|
|
argc,
|
|
argv,
|
|
desc),
|
|
vm);
|
|
boost::program_options::notify( vm);
|
|
|
|
if ( vm.count("help") ) {
|
|
std::cout << desc << std::endl;
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
if ( bind) bind_to_processor( 0);
|
|
|
|
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;
|
|
}
|