From 6e51c8222cd1ec01226266be59b93e0239bb180e Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Sun, 2 Feb 2014 19:34:17 +0100 Subject: [PATCH] print overhead of measurement in preformance tests --- example/cpp03/symmetric/simple.cpp | 27 +++---- .../performance_create_prealloc.cpp | 30 +++----- .../performance_create_protected.cpp | 22 +++--- .../performance_create_standard.cpp | 22 +++--- performance/asymmetric/performance_switch.cpp | 70 ++++++++----------- .../performance_create_segmented.cpp | 26 +++---- .../symmetric/performance_create_prealloc.cpp | 32 +++------ .../performance_create_protected.cpp | 24 +++---- .../symmetric/performance_create_standard.cpp | 24 +++---- performance/symmetric/performance_switch.cpp | 40 ++++++----- .../performance_create_segmented.cpp | 31 ++++---- 11 files changed, 153 insertions(+), 195 deletions(-) diff --git a/example/cpp03/symmetric/simple.cpp b/example/cpp03/symmetric/simple.cpp index fa84eb3..89e529d 100644 --- a/example/cpp03/symmetric/simple.cpp +++ b/example/cpp03/symmetric/simple.cpp @@ -28,8 +28,8 @@ struct X {} }; -typedef boost::coroutines::symmetric_coroutine< X&> coro1_t; -typedef boost::coroutines::symmetric_coroutine< X&> coro2_t; +typedef boost::coroutines::symmetric_coroutine< X* > coro1_t; +typedef boost::coroutines::symmetric_coroutine< X* > coro2_t; coro1_t * c1; coro2_t * c2; @@ -37,28 +37,31 @@ coro2_t * c2; void fn1( coro1_t::self_type & self) { Y y; - X x( 0); + X * x = 0; std::cout << "fn1: start" << std::endl; if ( self) x = self.get(); - std::cout << "fn1: i == " << x.i << std::endl; - self( * c2, X(x.i + 1)); + std::cout << "fn1: i == " << x->i << std::endl; + x->i += 1; + self( * c2, x); if ( self) x = self.get(); - std::cout << "fn1: i == " << x.i << std::endl; - self( * c2, X(x.i + 1)); + std::cout << "fn1: i == " << x->i << std::endl; + x->i += 1; + self( * c2, x); std::cout << "fn1: finish" << std::endl; } void fn2( coro2_t::self_type & self) { std::cout << "fn2: start" << std::endl; - X x( 0); + X * x = 0; if ( self) x = self.get(); - std::cout << "fn2: i == " << x.i << std::endl; - self( * c1, X(7)); + std::cout << "fn2: i == " << x->i << std::endl; + x->i = 7; + self( * c1, x); if ( self) x = self.get(); - std::cout << "fn2: i == " << x.i << std::endl; + std::cout << "fn2: i == " << x->i << std::endl; std::cout << "fn2: finish" << std::endl; } @@ -69,7 +72,7 @@ int main( int argc, char * argv[]) c1 = & c1_; c2 = & c2_; X x(3); - c1_( x); + c1_( & x); std::cout << "Done" << std::endl; return EXIT_SUCCESS; diff --git a/performance/asymmetric/performance_create_prealloc.cpp b/performance/asymmetric/performance_create_prealloc.cpp index 9c296b1..ad9ecc3 100644 --- a/performance/asymmetric/performance_create_prealloc.cpp +++ b/performance/asymmetric/performance_create_prealloc.cpp @@ -28,18 +28,10 @@ boost::uint64_t jobs = 1000; void fn( coro_type::push_type & c) { while ( true) c(); } -duration_type measure_time() +duration_type measure_time( duration_type overhead) { stack_allocator stack_alloc; - { - // cache warum-up - coro_type::pull_type c( fn, - boost::coroutines::attributes( - stack_allocator::default_stacksize(), unwind_stack, preserve_fpu), - stack_alloc); - } - time_point_type start( clock_type::now() ); for ( std::size_t i = 0; i < jobs; ++i) { coro_type::pull_type c( fn, @@ -54,18 +46,10 @@ duration_type measure_time() } # ifdef BOOST_CONTEXT_CYCLE -cycle_type measure_cycles() +cycle_type measure_cycles( cycle_type overhead) { stack_allocator stack_alloc; - { - // cache warum-up - coro_type::pull_type c( fn, - boost::coroutines::attributes( - stack_allocator::default_stacksize(), unwind_stack, preserve_fpu), - stack_alloc); - } - cycle_type start( cycles() ); for ( std::size_t i = 0; i < jobs; ++i) { coro_type::pull_type c( fn, @@ -73,7 +57,7 @@ cycle_type measure_cycles() stack_alloc); } cycle_type total = cycles() - start; - total -= overhead_cycle(); // overhead of measurement + total -= overhead; // overhead of measurement total /= jobs; // loops return total; @@ -111,10 +95,14 @@ int main( int argc, char * argv[]) if ( preserve) preserve_fpu = boost::coroutines::fpu_preserved; if ( ! unwind) unwind_stack = boost::coroutines::no_stack_unwind; - boost::uint64_t res = measure_time().count(); + duration_type overhead_c = overhead_clock(); + std::cout << "overhead " << overhead_c.count() << " nano seconds" << std::endl; + boost::uint64_t res = measure_time( overhead_c).count(); std::cout << "average of " << res << " nano seconds" << std::endl; #ifdef BOOST_CONTEXT_CYCLE - res = measure_cycles(); + cycle_type overhead_y = overhead_cycle(); + std::cout << "overhead " << overhead_y << " cpu cycles" << std::endl; + res = measure_cycles( overhead_y); std::cout << "average of " << res << " cpu cycles" << std::endl; #endif diff --git a/performance/asymmetric/performance_create_protected.cpp b/performance/asymmetric/performance_create_protected.cpp index d2a71b7..5fff8fa 100644 --- a/performance/asymmetric/performance_create_protected.cpp +++ b/performance/asymmetric/performance_create_protected.cpp @@ -27,14 +27,10 @@ boost::uint64_t jobs = 1000; void fn( coro_type::push_type & c) { while ( true) c(); } -duration_type measure_time() +duration_type measure_time( duration_type overhead) { stack_allocator stack_alloc; - // cache warum-up - coro_type::pull_type c( fn, - boost::coroutines::attributes( unwind_stack, preserve_fpu), stack_alloc); - time_point_type start( clock_type::now() ); for ( std::size_t i = 0; i < jobs; ++i) { coro_type::pull_type c( fn, @@ -48,21 +44,17 @@ duration_type measure_time() } # ifdef BOOST_CONTEXT_CYCLE -cycle_type measure_cycles() +cycle_type measure_cycles( cycle_type overhead) { stack_allocator stack_alloc; - // cache warum-up - coro_type::pull_type c( fn, - boost::coroutines::attributes( unwind_stack, preserve_fpu), stack_alloc); - cycle_type start( cycles() ); for ( std::size_t i = 0; i < jobs; ++i) { coro_type::pull_type c( fn, boost::coroutines::attributes( unwind_stack, preserve_fpu), stack_alloc); } cycle_type total = cycles() - start; - total -= overhead_cycle(); // overhead of measurement + total -= overhead; // overhead of measurement total /= jobs; // loops return total; @@ -100,10 +92,14 @@ int main( int argc, char * argv[]) if ( preserve) preserve_fpu = boost::coroutines::fpu_preserved; if ( ! unwind) unwind_stack = boost::coroutines::no_stack_unwind; - boost::uint64_t res = measure_time().count(); + duration_type overhead_c = overhead_clock(); + std::cout << "overhead " << overhead_c.count() << " nano seconds" << std::endl; + boost::uint64_t res = measure_time( overhead_c).count(); std::cout << "average of " << res << " nano seconds" << std::endl; #ifdef BOOST_CONTEXT_CYCLE - res = measure_cycles(); + cycle_type overhead_y = overhead_cycle(); + std::cout << "overhead " << overhead_y << " cpu cycles" << std::endl; + res = measure_cycles( overhead_y); std::cout << "average of " << res << " cpu cycles" << std::endl; #endif diff --git a/performance/asymmetric/performance_create_standard.cpp b/performance/asymmetric/performance_create_standard.cpp index d3b0abc..f0f13bd 100644 --- a/performance/asymmetric/performance_create_standard.cpp +++ b/performance/asymmetric/performance_create_standard.cpp @@ -27,14 +27,10 @@ boost::uint64_t jobs = 1000; void fn( coro_type::push_type & c) { while ( true) c(); } -duration_type measure_time() +duration_type measure_time( duration_type overhead) { stack_allocator stack_alloc; - // cache warum-up - coro_type::pull_type c( fn, - boost::coroutines::attributes( unwind_stack, preserve_fpu), stack_alloc); - time_point_type start( clock_type::now() ); for ( std::size_t i = 0; i < jobs; ++i) { coro_type::pull_type c( fn, @@ -48,21 +44,17 @@ duration_type measure_time() } # ifdef BOOST_CONTEXT_CYCLE -cycle_type measure_cycles() +cycle_type measure_cycles( cycle_type overhead) { stack_allocator stack_alloc; - // cache warum-up - coro_type::pull_type c( fn, - boost::coroutines::attributes( unwind_stack, preserve_fpu), stack_alloc); - cycle_type start( cycles() ); for ( std::size_t i = 0; i < jobs; ++i) { coro_type::pull_type c( fn, boost::coroutines::attributes( unwind_stack, preserve_fpu), stack_alloc); } cycle_type total = cycles() - start; - total -= overhead_cycle(); // overhead of measurement + total -= overhead; // overhead of measurement total /= jobs; // loops return total; @@ -100,10 +92,14 @@ int main( int argc, char * argv[]) if ( preserve) preserve_fpu = boost::coroutines::fpu_preserved; if ( ! unwind) unwind_stack = boost::coroutines::no_stack_unwind; - boost::uint64_t res = measure_time().count(); + duration_type overhead_c = overhead_clock(); + std::cout << "overhead " << overhead_c.count() << " nano seconds" << std::endl; + boost::uint64_t res = measure_time( overhead_c).count(); std::cout << "average of " << res << " nano seconds" << std::endl; #ifdef BOOST_CONTEXT_CYCLE - res = measure_cycles(); + cycle_type overhead_y = overhead_cycle(); + std::cout << "overhead " << overhead_y << " cpu cycles" << std::endl; + res = measure_cycles( overhead_y); std::cout << "average of " << res << " cpu cycles" << std::endl; #endif diff --git a/performance/asymmetric/performance_switch.cpp b/performance/asymmetric/performance_switch.cpp index 8653767..5c698fe 100644 --- a/performance/asymmetric/performance_switch.cpp +++ b/performance/asymmetric/performance_switch.cpp @@ -43,12 +43,10 @@ void fn_x( boost::coroutines::asymmetric_coroutine< X >::push_type & c) while ( true) c( x); } -duration_type measure_time_void() +duration_type measure_time_void( duration_type overhead) { - boost::coroutines::asymmetric_coroutine< void >::pull_type c( fn_void, boost::coroutines::attributes( preserve_fpu) ); - - // cache warum-up - c(); + boost::coroutines::asymmetric_coroutine< void >::pull_type c( fn_void, + boost::coroutines::attributes( preserve_fpu) ); time_point_type start( clock_type::now() ); for ( std::size_t i = 0; i < jobs; ++i) { @@ -62,12 +60,10 @@ duration_type measure_time_void() return total; } -duration_type measure_time_int() +duration_type measure_time_int( duration_type overhead) { - boost::coroutines::asymmetric_coroutine< int >::pull_type c( fn_int, boost::coroutines::attributes( preserve_fpu) ); - - // cache warum-up - c(); + boost::coroutines::asymmetric_coroutine< int >::pull_type c( fn_int, + boost::coroutines::attributes( preserve_fpu) ); time_point_type start( clock_type::now() ); for ( std::size_t i = 0; i < jobs; ++i) { @@ -81,12 +77,10 @@ duration_type measure_time_int() return total; } -duration_type measure_time_x() +duration_type measure_time_x( duration_type overhead) { - boost::coroutines::asymmetric_coroutine< X >::pull_type c( fn_x, boost::coroutines::attributes( preserve_fpu) ); - - // cache warum-up - c(); + 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) { @@ -101,57 +95,51 @@ duration_type measure_time_x() } # ifdef BOOST_CONTEXT_CYCLE -cycle_type measure_cycles_void() +cycle_type measure_cycles_void( cycle_type overhead) { - boost::coroutines::asymmetric_coroutine< void >::pull_type c( fn_void, boost::coroutines::attributes( preserve_fpu) ); - - // cache warum-up - c(); + boost::coroutines::asymmetric_coroutine< void >::pull_type c( fn_void, + boost::coroutines::attributes( preserve_fpu) ); cycle_type start( cycles() ); for ( std::size_t i = 0; i < jobs; ++i) { c(); } cycle_type total = cycles() - start; - total -= overhead_cycle(); // overhead of measurement + total -= overhead; // overhead of measurement total /= jobs; // loops total /= 2; // 2x jump_fcontext return total; } -cycle_type measure_cycles_int() +cycle_type measure_cycles_int( cycle_type overhead) { - boost::coroutines::asymmetric_coroutine< int >::pull_type c( fn_int, boost::coroutines::attributes( preserve_fpu) ); - - // cache warum-up - c(); + boost::coroutines::asymmetric_coroutine< int >::pull_type c( fn_int, + boost::coroutines::attributes( preserve_fpu) ); cycle_type start( cycles() ); for ( std::size_t i = 0; i < jobs; ++i) { c(); } cycle_type total = cycles() - start; - total -= overhead_cycle(); // overhead of measurement + total -= overhead; // overhead of measurement total /= jobs; // loops total /= 2; // 2x jump_fcontext return total; } -cycle_type measure_cycles_x() +cycle_type measure_cycles_x( cycle_type overhead) { - boost::coroutines::asymmetric_coroutine< X >::pull_type c( fn_x, boost::coroutines::attributes( preserve_fpu) ); - - // cache warum-up - c(); + boost::coroutines::asymmetric_coroutine< X >::pull_type c( fn_x, + boost::coroutines::attributes( preserve_fpu) ); cycle_type start( cycles() ); for ( std::size_t i = 0; i < jobs; ++i) { c(); } cycle_type total = cycles() - start; - total -= overhead_cycle(); // overhead of measurement + total -= overhead; // overhead of measurement total /= jobs; // loops total /= 2; // 2x jump_fcontext @@ -188,18 +176,22 @@ int main( int argc, char * argv[]) if ( preserve) preserve_fpu = boost::coroutines::fpu_preserved; - boost::uint64_t res = measure_time_void().count(); + 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().count(); + res = measure_time_int( overhead_c).count(); std::cout << "int: average of " << res << " nano seconds" << std::endl; - res = measure_time_x().count(); + res = measure_time_x( overhead_c).count(); std::cout << "X: average of " << res << " nano seconds" << std::endl; #ifdef BOOST_CONTEXT_CYCLE - res = measure_cycles_void(); + 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(); + res = measure_cycles_int( overhead_y); std::cout << "int: average of " << res << " cpu cycles" << std::endl; - res = measure_cycles_x(); + res = measure_cycles_x( overhead_y); std::cout << "X: average of " << res << " cpu cycles" << std::endl; #endif diff --git a/performance/asymmetric/segmented/performance_create_segmented.cpp b/performance/asymmetric/segmented/performance_create_segmented.cpp index 37f0a10..ea51f9f 100644 --- a/performance/asymmetric/segmented/performance_create_segmented.cpp +++ b/performance/asymmetric/segmented/performance_create_segmented.cpp @@ -23,14 +23,12 @@ boost::uint64_t jobs = 1000; void fn( boost::coroutines::asymmetric_coroutine< void >::push_type & c) { while ( true) c(); } -duration_type measure_time() +duration_type measure_time( duration_type overhead) { - // cache warum-up - boost::coroutines::asymmetric_coroutine< void >::pull_type c( fn, boost::coroutines::attributes( preserve_fpu) ); - time_point_type start( clock_type::now() ); for ( std::size_t i = 0; i < jobs; ++i) { - boost::coroutines::asymmetric_coroutine< void >::pull_type c( fn, boost::coroutines::attributes( preserve_fpu) ); + boost::coroutines::asymmetric_coroutine< void >::pull_type c( fn, + boost::coroutines::attributes( preserve_fpu) ); } duration_type total = clock_type::now() - start; total -= overhead_clock(); // overhead of measurement @@ -40,17 +38,15 @@ duration_type measure_time() } # ifdef BOOST_CONTEXT_CYCLE -cycle_type measure_cycles() +cycle_type measure_cycles( cycle_type overhead) { - // cache warum-up - boost::coroutines::asymmetric_coroutine< void >::pull_type c( fn, boost::coroutines::attributes( preserve_fpu) ); - cycle_type start( cycles() ); for ( std::size_t i = 0; i < jobs; ++i) { - boost::coroutines::asymmetric_coroutine< void >::pull_type c( fn, boost::coroutines::attributes( preserve_fpu) ); + boost::coroutines::asymmetric_coroutine< void >::pull_type c( fn, + boost::coroutines::attributes( preserve_fpu) ); } cycle_type total = cycles() - start; - total -= overhead_cycle(); // overhead of measurement + total -= overhead; // overhead of measurement total /= jobs; // loops return total; @@ -86,10 +82,14 @@ int main( int argc, char * argv[]) if ( preserve) preserve_fpu = boost::coroutines::fpu_preserved; - boost::uint64_t res = measure_time().count(); + duration_type overhead_c = overhead_clock(); + std::cout << "overhead " << overhead_c.count() << " nano seconds" << std::endl; + boost::uint64_t res = measure_time( overhead_c).count(); std::cout << "average of " << res << " nano seconds" << std::endl; #ifdef BOOST_CONTEXT_CYCLE - res = measure_cycles(); + cycle_type overhead_y = overhead_cycle(); + std::cout << "overhead " << overhead_y << " cpu cycles" << std::endl; + res = measure_cycles( overhead_y); std::cout << "average of " << res << " cpu cycles" << std::endl; #endif diff --git a/performance/symmetric/performance_create_prealloc.cpp b/performance/symmetric/performance_create_prealloc.cpp index c719eb6..307b0a6 100644 --- a/performance/symmetric/performance_create_prealloc.cpp +++ b/performance/symmetric/performance_create_prealloc.cpp @@ -27,18 +27,10 @@ boost::uint64_t jobs = 1000; void fn( coro_type::self_type &) {} -duration_type measure_time() +duration_type measure_time( duration_type overhead) { stack_allocator stack_alloc; - { - // cache warum-up - coro_type c( fn, - boost::coroutines::attributes( - stack_allocator::default_stacksize(), unwind_stack, preserve_fpu), - stack_alloc); - } - time_point_type start( clock_type::now() ); for ( std::size_t i = 0; i < jobs; ++i) { coro_type c( fn, @@ -46,25 +38,17 @@ duration_type measure_time() stack_alloc); } duration_type total = clock_type::now() - start; - total -= overhead_clock(); // overhead of measurement + total -= overhead; // overhead of measurement total /= jobs; // loops return total; } # ifdef BOOST_CONTEXT_CYCLE -cycle_type measure_cycles() +cycle_type measure_cycles( cycle_type overhead) { stack_allocator stack_alloc; - { - // cache warum-up - coro_type c( fn, - boost::coroutines::attributes( - stack_allocator::default_stacksize(), unwind_stack, preserve_fpu), - stack_alloc); - } - cycle_type start( cycles() ); for ( std::size_t i = 0; i < jobs; ++i) { coro_type c( fn, @@ -72,7 +56,7 @@ cycle_type measure_cycles() stack_alloc); } cycle_type total = cycles() - start; - total -= overhead_cycle(); // overhead of measurement + total -= overhead; // overhead of measurement total /= jobs; // loops return total; @@ -110,10 +94,14 @@ int main( int argc, char * argv[]) if ( preserve) preserve_fpu = boost::coroutines::fpu_preserved; if ( ! unwind) unwind_stack = boost::coroutines::no_stack_unwind; - boost::uint64_t res = measure_time().count(); + duration_type overhead_c = overhead_clock(); + std::cout << "overhead " << overhead_c.count() << " nano seconds" << std::endl; + boost::uint64_t res = measure_time( overhead_c).count(); std::cout << "average of " << res << " nano seconds" << std::endl; #ifdef BOOST_CONTEXT_CYCLE - res = measure_cycles(); + cycle_type overhead_y = overhead_cycle(); + std::cout << "overhead " << overhead_y << " cpu cycles" << std::endl; + res = measure_cycles( overhead_y); std::cout << "average of " << res << " cpu cycles" << std::endl; #endif diff --git a/performance/symmetric/performance_create_protected.cpp b/performance/symmetric/performance_create_protected.cpp index 9fa4763..fa68d4d 100644 --- a/performance/symmetric/performance_create_protected.cpp +++ b/performance/symmetric/performance_create_protected.cpp @@ -26,42 +26,34 @@ boost::uint64_t jobs = 1000; void fn( coro_type::self_type &) {} -duration_type measure_time() +duration_type measure_time( duration_type overhead) { stack_allocator stack_alloc; - // cache warum-up - coro_type c( fn, - boost::coroutines::attributes( unwind_stack, preserve_fpu), stack_alloc); - time_point_type start( clock_type::now() ); for ( std::size_t i = 0; i < jobs; ++i) { coro_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 -= overhead; // overhead of measurement total /= jobs; // loops return total; } # ifdef BOOST_CONTEXT_CYCLE -cycle_type measure_cycles() +cycle_type measure_cycles( cycle_type overhead) { stack_allocator stack_alloc; - // cache warum-up - coro_type c( fn, - boost::coroutines::attributes( unwind_stack, preserve_fpu), stack_alloc); - cycle_type start( cycles() ); for ( std::size_t i = 0; i < jobs; ++i) { coro_type c( fn, boost::coroutines::attributes( unwind_stack, preserve_fpu), stack_alloc); } cycle_type total = cycles() - start; - total -= overhead_cycle(); // overhead of measurement + total -= overhead; // overhead of measurement total /= jobs; // loops return total; @@ -99,10 +91,14 @@ int main( int argc, char * argv[]) if ( preserve) preserve_fpu = boost::coroutines::fpu_preserved; if ( ! unwind) unwind_stack = boost::coroutines::no_stack_unwind; - boost::uint64_t res = measure_time().count(); + duration_type overhead_c = overhead_clock(); + std::cout << "overhead " << overhead_c.count() << " nano seconds" << std::endl; + boost::uint64_t res = measure_time( overhead_c).count(); std::cout << "average of " << res << " nano seconds" << std::endl; #ifdef BOOST_CONTEXT_CYCLE - res = measure_cycles(); + cycle_type overhead_y = overhead_cycle(); + std::cout << "overhead " << overhead_y << " cpu cycles" << std::endl; + res = measure_cycles( overhead_y); std::cout << "average of " << res << " cpu cycles" << std::endl; #endif diff --git a/performance/symmetric/performance_create_standard.cpp b/performance/symmetric/performance_create_standard.cpp index dc7f048..9f47074 100644 --- a/performance/symmetric/performance_create_standard.cpp +++ b/performance/symmetric/performance_create_standard.cpp @@ -26,42 +26,34 @@ boost::uint64_t jobs = 1000; void fn( coro_type::self_type &) {} -duration_type measure_time() +duration_type measure_time( duration_type overhead) { stack_allocator stack_alloc; - // cache warum-up - coro_type c( fn, - boost::coroutines::attributes( unwind_stack, preserve_fpu), stack_alloc); - time_point_type start( clock_type::now() ); for ( std::size_t i = 0; i < jobs; ++i) { coro_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 -= overhead; // overhead of measurement total /= jobs; // loops return total; } # ifdef BOOST_CONTEXT_CYCLE -cycle_type measure_cycles() +cycle_type measure_cycles( cycle_type overhead) { stack_allocator stack_alloc; - // cache warum-up - coro_type c( fn, - boost::coroutines::attributes( unwind_stack, preserve_fpu), stack_alloc); - cycle_type start( cycles() ); for ( std::size_t i = 0; i < jobs; ++i) { coro_type c( fn, boost::coroutines::attributes( unwind_stack, preserve_fpu), stack_alloc); } cycle_type total = cycles() - start; - total -= overhead_cycle(); // overhead of measurement + total -= overhead; // overhead of measurement total /= jobs; // loops return total; @@ -99,10 +91,14 @@ int main( int argc, char * argv[]) if ( preserve) preserve_fpu = boost::coroutines::fpu_preserved; if ( ! unwind) unwind_stack = boost::coroutines::no_stack_unwind; - boost::uint64_t res = measure_time().count(); + duration_type overhead_c = overhead_clock(); + std::cout << "overhead " << overhead_c.count() << " nano seconds" << std::endl; + boost::uint64_t res = measure_time( overhead_c).count(); std::cout << "average of " << res << " nano seconds" << std::endl; #ifdef BOOST_CONTEXT_CYCLE - res = measure_cycles(); + cycle_type overhead_y = overhead_cycle(); + std::cout << "overhead " << overhead_y << " cpu cycles" << std::endl; + res = measure_cycles( overhead_y); std::cout << "average of " << res << " cpu cycles" << std::endl; #endif diff --git a/performance/symmetric/performance_switch.cpp b/performance/symmetric/performance_switch.cpp index 5e57a04..c7f22bb 100644 --- a/performance/symmetric/performance_switch.cpp +++ b/performance/symmetric/performance_switch.cpp @@ -42,7 +42,7 @@ void fn_int( boost::coroutines::symmetric_coroutine< int >::self_type &) void fn_x( boost::coroutines::symmetric_coroutine< X >::self_type &) {} -duration_type measure_time_void() +duration_type measure_time_void( duration_type overhead) { duration_type total = duration_type::zero(); for ( std::size_t i = 0; i < jobs; ++i) { @@ -51,15 +51,15 @@ duration_type measure_time_void() time_point_type start( clock_type::now() ); c(); total += clock_type::now() - start; - total -= overhead_clock(); // overhead of measurement } + total -= jobs * overhead; // overhead of measurement total /= jobs; // loops total /= 2; // 2x jump_fcontext return total; } -duration_type measure_time_int() +duration_type measure_time_int( duration_type overhead) { int i = 3; duration_type total = duration_type::zero(); @@ -69,15 +69,15 @@ duration_type measure_time_int() time_point_type start( clock_type::now() ); c( i); total += clock_type::now() - start; - total -= overhead_clock(); // overhead of measurement } + total -= jobs * overhead; // overhead of measurement total /= jobs; // loops total /= 2; // 2x jump_fcontext return total; } -duration_type measure_time_x() +duration_type measure_time_x( duration_type overhead) { X x("abc"); duration_type total = duration_type::zero(); @@ -87,8 +87,8 @@ duration_type measure_time_x() time_point_type start( clock_type::now() ); c(); total += clock_type::now() - start; - total -= overhead_clock(); // overhead of measurement } + total -= jobs * overhead; // overhead of measurement total /= jobs; // loops total /= 2; // 2x jump_fcontext @@ -96,7 +96,7 @@ duration_type measure_time_x() } # ifdef BOOST_CONTEXT_CYCLE -cycle_type measure_cycles_void() +cycle_type measure_cycles_void( cycle_type overhead) { cycle_type total = 0; for ( std::size_t i = 0; i < jobs; ++i) { @@ -105,15 +105,15 @@ cycle_type measure_cycles_void() cycle_type start( cycles() ); c(); total += cycles() - start; - total -= overhead_cycle(); // overhead of measurement } + total -= jobs * overhead; // overhead of measurement total /= jobs; // loops total /= 2; // 2x jump_fcontext return total; } -cycle_type measure_cycles_int() +cycle_type measure_cycles_int( cycle_type overhead) { int i = 3; cycle_type total = 0; @@ -123,15 +123,15 @@ cycle_type measure_cycles_int() cycle_type start( cycles() ); c( i); total += cycles() - start; - total -= overhead_cycle(); // overhead of measurement } + total -= jobs * overhead; // overhead of measurement total /= jobs; // loops total /= 2; // 2x jump_fcontext return total; } -cycle_type measure_cycles_x() +cycle_type measure_cycles_x( cycle_type overhead) { X x("abc"); cycle_type total = 0; @@ -141,8 +141,8 @@ cycle_type measure_cycles_x() cycle_type start( cycles() ); c( x); total += cycles() - start; - total -= overhead_cycle(); // overhead of measurement } + total -= jobs * overhead; // overhead of measurement total /= jobs; // loops total /= 2; // 2x jump_fcontext @@ -179,18 +179,22 @@ int main( int argc, char * argv[]) if ( preserve) preserve_fpu = boost::coroutines::fpu_preserved; - boost::uint64_t res = measure_time_void().count(); + 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().count(); + res = measure_time_int( overhead_c).count(); std::cout << "int: average of " << res << " nano seconds" << std::endl; - res = measure_time_x().count(); + res = measure_time_x( overhead_c).count(); std::cout << "X: average of " << res << " nano seconds" << std::endl; #ifdef BOOST_CONTEXT_CYCLE - res = measure_cycles_void(); + 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(); + res = measure_cycles_int( overhead_y); std::cout << "int: average of " << res << " cpu cycles" << std::endl; - res = measure_cycles_x(); + res = measure_cycles_x( overhead_y); std::cout << "X: average of " << res << " cpu cycles" << std::endl; #endif diff --git a/performance/symmetric/segmented/performance_create_segmented.cpp b/performance/symmetric/segmented/performance_create_segmented.cpp index a068f42..53afe57 100644 --- a/performance/symmetric/segmented/performance_create_segmented.cpp +++ b/performance/symmetric/segmented/performance_create_segmented.cpp @@ -20,37 +20,32 @@ boost::coroutines::flag_fpu_t preserve_fpu = boost::coroutines::fpu_not_preserved; boost::uint64_t jobs = 1000; -void fn( boost::coroutines::coroutine< void >::push_type & c) -{ while ( true) c(); } +void fn( boost::coroutines::symmetric_coroutine< void >::self_type &) {} -duration_type measure_time() +duration_type measure_time( duration_type overhead) { - // cache warum-up - boost::coroutines::coroutine< void >::pull_type c( fn, boost::coroutines::attributes( preserve_fpu) ); - time_point_type start( clock_type::now() ); for ( std::size_t i = 0; i < jobs; ++i) { - boost::coroutines::coroutine< void >::pull_type c( fn, boost::coroutines::attributes( preserve_fpu) ); + boost::coroutines::symmetric_coroutine< void > c( fn, + boost::coroutines::attributes( preserve_fpu) ); } duration_type total = clock_type::now() - start; - total -= overhead_clock(); // overhead of measurement + total -= overhead; // overhead of measurement total /= jobs; // loops return total; } # ifdef BOOST_CONTEXT_CYCLE -cycle_type measure_cycles() +cycle_type measure_cycles( cycle_type overhead) { - // cache warum-up - boost::coroutines::coroutine< void >::pull_type c( fn, boost::coroutines::attributes( preserve_fpu) ); - cycle_type start( cycles() ); for ( std::size_t i = 0; i < jobs; ++i) { - boost::coroutines::coroutine< void >::pull_type c( fn, boost::coroutines::attributes( preserve_fpu) ); + boost::coroutines::symmetric_coroutine< void > c( fn, + boost::coroutines::attributes( preserve_fpu) ); } cycle_type total = cycles() - start; - total -= overhead_cycle(); // overhead of measurement + total -= overhead; // overhead of measurement total /= jobs; // loops return total; @@ -86,10 +81,14 @@ int main( int argc, char * argv[]) if ( preserve) preserve_fpu = boost::coroutines::fpu_preserved; - boost::uint64_t res = measure_time().count(); + duration_type overhead_c = overhead_clock(); + std::cout << "overhead " << overhead_c.count() << " nano seconds" << std::endl; + boost::uint64_t res = measure_time( overhead_c).count(); std::cout << "average of " << res << " nano seconds" << std::endl; #ifdef BOOST_CONTEXT_CYCLE - res = measure_cycles(); + cycle_type overhead_y = overhead_cycle(); + std::cout << "overhead " << overhead_y << " cpu cycles" << std::endl; + res = measure_cycles( overhead_y); std::cout << "average of " << res << " cpu cycles" << std::endl; #endif