From e74929f66aee3e7e1e17650b29d972b6f946cc29 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Sun, 26 Jan 2014 11:16:31 +0100 Subject: [PATCH] enable/disable stack unwinding in performance tests --- include/boost/coroutine/attributes.hpp | 9 +++++++++ performance/performance_create_prealloc.cpp | 13 ++++++++----- performance/performance_create_protected.cpp | 13 ++++++++----- performance/performance_create_simple.cpp | 13 ++++++++----- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/include/boost/coroutine/attributes.hpp b/include/boost/coroutine/attributes.hpp index 2855082..207f581 100644 --- a/include/boost/coroutine/attributes.hpp +++ b/include/boost/coroutine/attributes.hpp @@ -74,6 +74,15 @@ struct attributes do_unwind( do_unwind_), preserve_fpu( preserve_fpu_) {} + + explicit attributes( + std::size_t size_, + flag_unwind_t do_unwind_, + flag_fpu_t preserve_fpu_) BOOST_NOEXCEPT : + size( size_), + do_unwind( do_unwind_), + preserve_fpu( preserve_fpu_) + {} }; }} diff --git a/performance/performance_create_prealloc.cpp b/performance/performance_create_prealloc.cpp index 66d7e14..32f9daa 100644 --- a/performance/performance_create_prealloc.cpp +++ b/performance/performance_create_prealloc.cpp @@ -22,6 +22,7 @@ typedef preallocated_stack_allocator< 64 * 1024 > stack_allocator; typedef boost::coroutines::coroutine< void, stack_allocator > coroutine; boost::coroutines::flag_fpu_t preserve_fpu = boost::coroutines::fpu_not_preserved; +boost::coroutines::flag_unwind_t unwind_stack = boost::coroutines::stack_unwind; boost::uint64_t jobs = 1000; void fn( coroutine::push_type & c) @@ -33,13 +34,13 @@ duration_type measure_time() // cache warum-up coroutine::pull_type c( fn, - boost::coroutines::attributes( stack_allocator::default_stacksize(), preserve_fpu), + 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) { coroutine::pull_type c( fn, - boost::coroutines::attributes( stack_allocator::default_stacksize(), preserve_fpu), + boost::coroutines::attributes( stack_allocator::default_stacksize(), unwind_stack, preserve_fpu), stack_alloc); } duration_type total = clock_type::now() - start; @@ -56,13 +57,13 @@ cycle_type measure_cycles() // cache warum-up coroutine::pull_type c( fn, - boost::coroutines::attributes( stack_allocator::default_stacksize(), preserve_fpu), + 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) { coroutine::pull_type c( fn, - boost::coroutines::attributes( stack_allocator::default_stacksize(), preserve_fpu), + boost::coroutines::attributes( stack_allocator::default_stacksize(), unwind_stack, preserve_fpu), stack_alloc); } cycle_type total = cycles() - start; @@ -79,11 +80,12 @@ int main( int argc, char * argv[]) { bind_to_processor( 0); - bool preserve = false; + bool preserve = false, unwind = true; boost::program_options::options_description desc("allowed options"); desc.add_options() ("help", "help message") ("fpu,f", boost::program_options::value< bool >( & preserve), "preserve FPU registers") + ("unwind,u", boost::program_options::value< bool >( & unwind), "unwind stack") ("jobs,j", boost::program_options::value< boost::uint64_t >( & jobs), "jobs to run"); boost::program_options::variables_map vm; @@ -101,6 +103,7 @@ 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(); std::cout << "average of " << res << " nano seconds" << std::endl; diff --git a/performance/performance_create_protected.cpp b/performance/performance_create_protected.cpp index abc465a..24da6d7 100644 --- a/performance/performance_create_protected.cpp +++ b/performance/performance_create_protected.cpp @@ -21,6 +21,7 @@ typedef boost::coroutines::protected_stack_allocator stack_allocator; typedef boost::coroutines::coroutine< void, stack_allocator > coroutine; boost::coroutines::flag_fpu_t preserve_fpu = boost::coroutines::fpu_not_preserved; +boost::coroutines::flag_unwind_t unwind_stack = boost::coroutines::stack_unwind; boost::uint64_t jobs = 1000; void fn( coroutine::push_type & c) @@ -31,11 +32,11 @@ duration_type measure_time() stack_allocator stack_alloc; // cache warum-up - coroutine::pull_type c( fn, boost::coroutines::attributes( preserve_fpu), stack_alloc); + coroutine::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) { - coroutine::pull_type c( fn, boost::coroutines::attributes( preserve_fpu), stack_alloc); + coroutine::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 @@ -50,11 +51,11 @@ cycle_type measure_cycles() stack_allocator stack_alloc; // cache warum-up - coroutine::pull_type c( fn, boost::coroutines::attributes( preserve_fpu), stack_alloc); + coroutine::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) { - coroutine::pull_type c( fn, boost::coroutines::attributes( preserve_fpu), stack_alloc); + coroutine::pull_type c( fn, boost::coroutines::attributes( unwind_stack, preserve_fpu), stack_alloc); } cycle_type total = cycles() - start; total -= overhead_cycle(); // overhead of measurement @@ -70,11 +71,12 @@ int main( int argc, char * argv[]) { bind_to_processor( 0); - bool preserve = false; + bool preserve = false, unwind = true; boost::program_options::options_description desc("allowed options"); desc.add_options() ("help", "help message") ("fpu,f", boost::program_options::value< bool >( & preserve), "preserve FPU registers") + ("unwind,u", boost::program_options::value< bool >( & unwind), "unwind stack") ("jobs,j", boost::program_options::value< boost::uint64_t >( & jobs), "jobs to run"); boost::program_options::variables_map vm; @@ -92,6 +94,7 @@ 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(); std::cout << "average of " << res << " nano seconds" << std::endl; diff --git a/performance/performance_create_simple.cpp b/performance/performance_create_simple.cpp index f7e6cad..034ba39 100644 --- a/performance/performance_create_simple.cpp +++ b/performance/performance_create_simple.cpp @@ -21,6 +21,7 @@ typedef boost::coroutines::simple_stack_allocator stack_allocator; typedef boost::coroutines::coroutine< void, stack_allocator > coroutine; boost::coroutines::flag_fpu_t preserve_fpu = boost::coroutines::fpu_not_preserved; +boost::coroutines::flag_unwind_t unwind_stack = boost::coroutines::stack_unwind; boost::uint64_t jobs = 1000; void fn( coroutine::push_type & c) @@ -31,11 +32,11 @@ duration_type measure_time() stack_allocator stack_alloc; // cache warum-up - coroutine::pull_type c( fn, boost::coroutines::attributes( preserve_fpu), stack_alloc); + coroutine::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) { - coroutine::pull_type c( fn, boost::coroutines::attributes( preserve_fpu), stack_alloc); + coroutine::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 @@ -50,11 +51,11 @@ cycle_type measure_cycles() stack_allocator stack_alloc; // cache warum-up - coroutine::pull_type c( fn, boost::coroutines::attributes( preserve_fpu), stack_alloc); + coroutine::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) { - coroutine::pull_type c( fn, boost::coroutines::attributes( preserve_fpu), stack_alloc); + coroutine::pull_type c( fn, boost::coroutines::attributes( unwind_stack, preserve_fpu), stack_alloc); } cycle_type total = cycles() - start; total -= overhead_cycle(); // overhead of measurement @@ -70,11 +71,12 @@ int main( int argc, char * argv[]) { bind_to_processor( 0); - bool preserve = false; + bool preserve = false, unwind = true; boost::program_options::options_description desc("allowed options"); desc.add_options() ("help", "help message") ("fpu,f", boost::program_options::value< bool >( & preserve), "preserve FPU registers") + ("unwind,u", boost::program_options::value< bool >( & unwind), "unwind stack") ("jobs,j", boost::program_options::value< boost::uint64_t >( & jobs), "jobs to run"); boost::program_options::variables_map vm; @@ -92,6 +94,7 @@ 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(); std::cout << "average of " << res << " nano seconds" << std::endl;