foramting code

This commit is contained in:
Oliver Kowalke 2016-03-04 18:24:25 +01:00
parent 5526765c10
commit 6c15fe0a5c
3 changed files with 24 additions and 69 deletions

View File

@ -18,8 +18,7 @@
#define JOBS BOOST_PP_LIMIT_REPEAT
#endif
#define WAIT(z, n, _) \
{ \
#define WAIT(z, n, _) { \
boost::fibers::packaged_task< void() > pt( worker); \
boost::fibers::future< void > f( pt.get_future() ); \
boost::fibers::fiber( std::move( pt) ).detach(); \
@ -32,32 +31,24 @@
void worker() {}
duration_type measure( duration_type overhead)
{
duration_type measure( duration_type overhead) {
boost::fibers::fiber( worker).join();
duration_type result = duration_type::zero();
BOOST_PP_REPEAT_FROM_TO(1, JOBS, WAIT, _)
result /= JOBS; // loops
return result;
}
int main( int argc, char * argv[])
{
try
{
int main( int argc, char * argv[]) {
try {
duration_type overhead = overhead_clock();
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;
}
catch ( std::exception const& e)
{ std::cerr << "exception: " << e.what() << std::endl; }
catch (...)
{ std::cerr << "unhandled exception" << std::endl; }
return EXIT_FAILURE;
}

View File

@ -31,7 +31,10 @@
#define JOIN(z, n, _) \
BOOST_PP_CAT(f,n) .join();
void worker() {}
duration_type measure( duration_type overhead) {
boost::fibers::fiber( worker).join();
duration_type total = duration_type::zero();
BOOST_PP_REPEAT_FROM_TO(1, JOBS, CREATE, _)
BOOST_PP_REPEAT_FROM_TO(1, JOBS, JOIN, _);

View File

@ -21,124 +21,86 @@
void worker() {}
duration_type measure10( duration_type overhead)
{
duration_type measure10( duration_type overhead) {
boost::fibers::fiber( worker).join();
BOOST_PP_REPEAT_FROM_TO(1, 10, CREATE, _);
time_point_type start( clock_type::now() );
BOOST_PP_REPEAT_FROM_TO(1, 10, JOIN, _);
duration_type total = clock_type::now() - start;
total -= overhead_clock(); // overhead of measurement
total /= 10; // loops
return total;
}
duration_type measure50( duration_type overhead)
{
duration_type measure50( duration_type overhead) {
boost::fibers::fiber( 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 measure100( duration_type overhead)
{
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;
}
duration_type measure500( duration_type overhead)
{
duration_type measure500( duration_type overhead) {
boost::fibers::fiber( worker).join();
#include "fiber_create_500.ipp"
time_point_type start( clock_type::now() );
#include "fiber_join_500.ipp"
duration_type total = clock_type::now() - start;
total -= overhead_clock(); // overhead of measurement
total /= 500; // loops
return total;
}
duration_type measure1000( duration_type overhead)
{
duration_type measure1000( duration_type overhead) {
boost::fibers::fiber( worker).join();
#include "fiber_create_1000.ipp"
time_point_type start( clock_type::now() );
#include "fiber_join_1000.ipp"
duration_type total = clock_type::now() - start;
total -= overhead_clock(); // overhead of measurement
total /= 1000; // loops
return total;
}
duration_type measure5000( duration_type overhead)
{
duration_type measure5000( duration_type overhead) {
boost::fibers::fiber( worker).join();
#include "fiber_create_5000.ipp"
time_point_type start( clock_type::now() );
#include "fiber_join_5000.ipp"
duration_type total = clock_type::now() - start;
total -= overhead_clock(); // overhead of measurement
total /= 5000; // loops
return total;
}
duration_type measure10000( duration_type overhead)
{
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;
}
int main( int argc, char * argv[])
{
try
{
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();
@ -153,12 +115,11 @@ int main( int argc, char * argv[])
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;
}
catch ( std::exception const& e)
{ std::cerr << "exception: " << e.what() << std::endl; }
catch (...)
{ std::cerr << "unhandled exception" << std::endl; }
return EXIT_FAILURE;
}