diff options
Diffstat (limited to 'libs/context/performance/fcontext')
-rw-r--r-- | libs/context/performance/fcontext/Jamfile.v2 | 8 | ||||
-rw-r--r-- | libs/context/performance/fcontext/performance_fcontext.cpp | 89 |
2 files changed, 84 insertions, 13 deletions
diff --git a/libs/context/performance/fcontext/Jamfile.v2 b/libs/context/performance/fcontext/Jamfile.v2 index 4d1ceb52f..13b1ef355 100644 --- a/libs/context/performance/fcontext/Jamfile.v2 +++ b/libs/context/performance/fcontext/Jamfile.v2 @@ -18,9 +18,15 @@ project boost/context/performance/fcontext <library>/boost/chrono//boost_chrono <library>/boost/context//boost_context <library>/boost/program_options//boost_program_options + <toolset>gcc,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>gcc,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS + <toolset>clang,<segmented-stacks>on:<cxxflags>-fsplit-stack + <toolset>clang,<segmented-stacks>on:<cxxflags>-DBOOST_USE_SEGMENTED_STACKS <link>static - <linkflags>"-lrt" + <optimization>speed <threading>multi + <variant>release + <cxxflags>-DBOOST_DISABLE_ASSERTS ; alias sources diff --git a/libs/context/performance/fcontext/performance_fcontext.cpp b/libs/context/performance/fcontext/performance_fcontext.cpp index e8dbae240..3e370c136 100644 --- a/libs/context/performance/fcontext/performance_fcontext.cpp +++ b/libs/context/performance/fcontext/performance_fcontext.cpp @@ -27,11 +27,25 @@ boost::uint64_t jobs = 1000; boost::context::fcontext_t fcm = 0; boost::context::fcontext_t fc = 0; -static void fn( intptr_t) -{ while ( true) boost::context::jump_fcontext( & fc, fcm, 7, preserve_fpu); } +#if __cplusplus >= 201103L +boost::context::execution_context * mctx = nullptr; +#endif -duration_type measure_time() -{ +static void foo( intptr_t) { + while ( true) { + boost::context::jump_fcontext( & fc, fcm, 7, preserve_fpu); + } +} + +#if __cplusplus >= 201103L +static void bar() { + while ( true) { + mctx->resume(); + } +} +#endif + +duration_type measure_time_fc() { // cache warum-up boost::context::jump_fcontext( & fcm, fc, 7, preserve_fpu); @@ -47,9 +61,30 @@ duration_type measure_time() return total; } +#if __cplusplus >= 201103L +duration_type measure_time_ec() { + boost::context::execution_context ctx( boost::context::execution_context::current() ); + mctx = & ctx; + // cache warum-up + boost::context::fixedsize_stack alloc; + boost::context::execution_context ectx( alloc, bar); + ectx.resume(); + + time_point_type start( clock_type::now() ); + for ( std::size_t i = 0; i < jobs; ++i) { + ectx.resume(); + } + duration_type total = clock_type::now() - start; + total -= overhead_clock(); // overhead of measurement + total /= jobs; // loops + total /= 2; // 2x jump_fcontext + + return total; +} +#endif + #ifdef BOOST_CONTEXT_CYCLE -cycle_type measure_cycles() -{ +cycle_type measure_cycles_fc() { // cache warum-up boost::context::jump_fcontext( & fcm, fc, 7, preserve_fpu); @@ -64,6 +99,28 @@ cycle_type measure_cycles() return total; } + +# if __cplusplus >= 201103L +cycle_type measure_cycles_ec() { + boost::context::execution_context ctx( boost::context::execution_context::current() ); + mctx = & ctx; + // cache warum-up + boost::context::fixedsize_stack alloc; + boost::context::execution_context ectx( alloc, bar); + ectx.resume(); + + cycle_type start( cycles() ); + for ( std::size_t i = 0; i < jobs; ++i) { + ectx.resume(); + } + cycle_type total = cycles() - start; + total -= overhead_cycle(); // overhead of measurement + total /= jobs; // loops + total /= 2; // 2x jump_fcontext + + return total; +} +# endif #endif int main( int argc, char * argv[]) @@ -96,13 +153,21 @@ int main( int argc, char * argv[]) fc = boost::context::make_fcontext( stack_alloc.allocate( stack_allocator::default_stacksize() ), stack_allocator::default_stacksize(), - fn); - - boost::uint64_t res = measure_time().count(); - std::cout << "average of " << res << " nano seconds" << std::endl; + foo); + + boost::uint64_t res = measure_time_fc().count(); + std::cout << "fcontext_t: average of " << res << " nano seconds" << std::endl; +# if __cplusplus >= 201103L + res = measure_time_ec().count(); + std::cout << "execution_context: average of " << res << " nano seconds" << std::endl; +# endif #ifdef BOOST_CONTEXT_CYCLE - res = measure_cycles(); - std::cout << "average of " << res << " cpu cycles" << std::endl; + res = measure_cycles_fc(); + std::cout << "fcontext_t: average of " << res << " cpu cycles" << std::endl; +# if __cplusplus >= 201103L + res = measure_cycles_ec(); + std::cout << "execution_context: average of " << res << " cpu cycles" << std::endl; +# endif #endif return EXIT_SUCCESS; |