Beispiel #1
0
int main( int argc, char * argv[])
{
    try
    {
        duration_type overhead = overhead_clock();

        boost::uint64_t res = measure10( overhead).count();
        std::cout << "10 jobs: average of " << res << " nano seconds" << std::endl;
        res = measure50( overhead).count();
        std::cout << "50 jobs: average of " << res << " nano seconds" << std::endl;
        res = measure100( overhead).count();
        std::cout << "100 jobs: average of " << res << " nano seconds" << std::endl;
        res = measure500( overhead).count();
        std::cout << "500 jobs: average of " << res << " nano seconds" << std::endl;
        res = measure1000( overhead).count();
        std::cout << "1000 jobs: average of " << res << " nano seconds" << std::endl;
        res = measure5000( overhead).count();
        std::cout << "5000 jobs: average of " << res << " nano seconds" << std::endl;
        res = measure10000( overhead).count();
        std::cout << "10000 jobs: 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;
}
int main( int argc, char * argv[])
{
    try
    {
        bool preserve = false, 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")
            ("fpu,f", boost::program_options::value< bool >( & preserve), "preserve FPU registers")
            ("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 ( preserve) preserve_fpu = boost::coroutines::fpu_preserved;
        if ( bind) bind_to_processor( 0);

        duration_type overhead_c = overhead_clock();
        std::cout << "overhead " << overhead_c.count() << " nano seconds" << std::endl;
        boost::uint64_t res = measure_time_void( overhead_c).count();
        std::cout << "void: average of " << res << " nano seconds" << std::endl;
        res = measure_time_int( overhead_c).count();
        std::cout << "int: average of " << res << " nano seconds" << std::endl;
        res = measure_time_x( overhead_c).count();
        std::cout << "X: average of " << res << " nano seconds" << std::endl;
#ifdef BOOST_CONTEXT_CYCLE
        cycle_type overhead_y = overhead_cycle();
        std::cout << "overhead " << overhead_y << " cpu cycles" << std::endl;
        res = measure_cycles_void( overhead_y);
        std::cout << "void: average of " << res << " cpu cycles" << std::endl;
        res = measure_cycles_int( overhead_y);
        std::cout << "int: average of " << res << " cpu cycles" << std::endl;
        res = measure_cycles_x( overhead_y);
        std::cout << "X: average of " << res << " cpu cycles" << std::endl;
#endif

        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;
}
Beispiel #3
0
duration_type measure10000( duration_type overhead) {
    boost::fibers::fiber( worker).join();
#include "fiber_create_10000.ipp"
    time_point_type start( clock_type::now() );
#include "fiber_join_10000.ipp"
    duration_type total = clock_type::now() - start;
    total -= overhead_clock(); // overhead of measurement
    total /= 10000;  // loops
    return total;
}
Beispiel #4
0
duration_type measure100( duration_type overhead) {
    boost::fibers::fiber( worker).join();
    BOOST_PP_REPEAT_FROM_TO(1, 100, CREATE, _);
    time_point_type start( clock_type::now() );
    BOOST_PP_REPEAT_FROM_TO(1, 100, JOIN, _);
    duration_type total = clock_type::now() - start;
    total -= overhead_clock(); // overhead of measurement
    total /= 100;  // loops
    return total;
}
Beispiel #5
0
duration_type measure_time_void( duration_type overhead) {
    boost::coroutines2::coroutine< void >::pull_type c{ fn };
    time_point_type start( clock_type::now() );
    for ( std::size_t i = 0; i < jobs; ++i) {
        c();
    }
    duration_type total = clock_type::now() - start;
    total -= overhead_clock(); // overhead of measurement
    total /= jobs;  // loops
    total /= 2;  // 2x jump_fcontext

    return total;
}
duration_type measure_time_fc() {
    // cache warum-up
    boost::context::jump_fcontext( & fcm, fc, 7, preserve_fpu);
        
    time_point_type start( clock_type::now() );
    for ( std::size_t i = 0; i < jobs; ++i) {
        boost::context::jump_fcontext( & fcm, fc, 7, preserve_fpu);
    }
    duration_type total = clock_type::now() - start;
    total -= overhead_clock(); // overhead of measurement
    total /= jobs;  // loops
    total /= 2;  // 2x jump_fcontext

    return total;
}
Beispiel #7
0
duration_type measure500( duration_type overhead)
{
    std::thread( worker).join();

#include "thread_create_500.ipp"

    time_point_type start( clock_type::now() );
#include "thread_join_500.ipp"
    duration_type total = clock_type::now() - start;

    total -= overhead_clock(); // overhead of measurement
    total /= 500;  // loops

    return total;
}
Beispiel #8
0
duration_type measure50( duration_type overhead)
{
    std::thread( worker).join();

    BOOST_PP_REPEAT_FROM_TO(1, 50, CREATE, _);

    time_point_type start( clock_type::now() );
    BOOST_PP_REPEAT_FROM_TO(1, 50, JOIN, _);
    duration_type total = clock_type::now() - start;

    total -= overhead_clock(); // overhead of measurement
    total /= 50;  // loops

    return total;
}
duration_type measure_time( duration_type overhead)
{
    stack_allocator stack_alloc;

    time_point_type start( clock_type::now() );
    for ( std::size_t i = 0; i < jobs; ++i) {
        coro_type::pull_type c( fn,
            boost::coroutines::attributes( unwind_stack, preserve_fpu),
            stack_alloc);
    }
    duration_type total = clock_type::now() - start;
    total -= overhead_clock(); // overhead of measurement
    total /= jobs;  // loops

    return total;
}
duration_type measure_time_x( duration_type overhead)
{
    boost::coroutines::asymmetric_coroutine< X >::pull_type c( fn_x,
            boost::coroutines::attributes( preserve_fpu) );
        
    time_point_type start( clock_type::now() );
    for ( std::size_t i = 0; i < jobs; ++i) {
        c();
    }
    duration_type total = clock_type::now() - start;
    total -= overhead_clock(); // overhead of measurement
    total /= jobs;  // loops
    total /= 2;  // 2x jump_fcontext

    return total;
}
Beispiel #11
0
duration_type measure_time_ec() {
    boost::context::execution_context ctx( boost::context::execution_context::current() );
    // cache warum-up
    boost::context::fixedsize_stack alloc;
    boost::context::execution_context ectx( std::allocator_arg, alloc, bar);
    ectx( & ctx);
        
    time_point_type start( clock_type::now() );
    for ( std::size_t i = 0; i < jobs; ++i) {
        ectx( & ctx);
    }
    duration_type total = clock_type::now() - start;
    total -= overhead_clock(); // overhead of measurement
    total /= jobs;  // loops
    total /= 2;  // 2x jump_fcontext

    return total;
}
duration_type measure_time_fc() {
    stack_allocator stack_alloc;
    boost::context::detail::fcontext_t ctx = boost::context::detail::make_fcontext(
            stack_alloc.allocate( stack_allocator::default_stacksize() ),
            stack_allocator::default_stacksize(),
            foo);

    // cache warum-up
    boost::context::detail::transfer_t t = boost::context::detail::jump_fcontext( ctx, 0);

    time_point_type start( clock_type::now() );
    for ( std::size_t i = 0; i < jobs; ++i) {
        t = boost::context::detail::jump_fcontext( t.fctx, 0);
    }
    duration_type total = clock_type::now() - start;
    total -= overhead_clock(); // overhead of measurement
    total /= jobs;  // loops
    total /= 2;  // 2x jump_fcontext

    return total;
}