diff --git a/dep/boost/CMakeLists.txt b/dep/boost/CMakeLists.txt index 7aa0886..451ca5f 100644 --- a/dep/boost/CMakeLists.txt +++ b/dep/boost/CMakeLists.txt @@ -18,7 +18,8 @@ endif() find_package(Boost 1.68 REQUIRED COMPONENTS system - iostreams) + iostreams + thread) if (${Boost_FOUND}) add_library(boost INTERFACE) @@ -26,7 +27,8 @@ if (${Boost_FOUND}) target_link_libraries(boost INTERFACE Boost::system - Boost::iostreams) + Boost::iostreams + Boost::thread) target_compile_definitions(boost INTERFACE @@ -34,5 +36,8 @@ if (${Boost_FOUND}) BOOST_ASIO_DISABLE_BOOST_DATE_TIME BOOST_ASIO_DISABLE_BOOST_REGEX BOOST_RANGE_ENABLE_CONCEPT_ASSERT=0 - BOOST_FILESYSTEM_NO_DEPRECATED) + BOOST_THREAD_PROVIDES_FUTURE + BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION + BOOST_FILESYSTEM_NO_DEPRECATED + BOOST_THREAD_VERSION=4) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f24a523..069d43b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,3 +2,4 @@ add_subdirectory(playground) add_subdirectory(threads) add_subdirectory(unit-test) add_subdirectory(mock) +add_subdirectory(simple-benchmark) diff --git a/test/simple-benchmark/CMakeLists.txt b/test/simple-benchmark/CMakeLists.txt new file mode 100644 index 0000000..f793846 --- /dev/null +++ b/test/simple-benchmark/CMakeLists.txt @@ -0,0 +1,16 @@ +if (NOT CTI_CONTINUABLE_WITH_BENCHMARKS) + return() +endif() + +add_executable(benchmark-simple + ${CMAKE_CURRENT_LIST_DIR}/benchmark-simple.cpp) + +target_link_libraries(benchmark-simple + PRIVATE + benchmark + benchmark_main + boost + continuable + continuable-features-flags + continuable-features-warnings + continuable-features-noexcept) diff --git a/test/simple-benchmark/benchmark-simple.cpp b/test/simple-benchmark/benchmark-simple.cpp new file mode 100644 index 0000000..24f1f94 --- /dev/null +++ b/test/simple-benchmark/benchmark-simple.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +#include + +static auto do_sth_continuable() { + return cti::make_continuable([](auto&& promise) { + // + promise.set_value(); + }); +} + +static void bm_continuable(benchmark::State& state) { + for (auto _ : state) { + cti::continuable<> cont = do_sth_continuable() + .then([] { + // ... + return do_sth_continuable(); + }) + .then([] { + // ... + return do_sth_continuable(); + }); + } +} + +BENCHMARK(bm_continuable); + +static boost::future do_sth_future() { + boost::promise p; + boost::future fu = p.get_future(); + p.set_value(); + + return fu; +} + +static void bm_future(benchmark::State& state) { + for (auto _ : state) { + auto fut = do_sth_future() + .then([](auto&&) { + // ... + return do_sth_future(); + }) + .then([](auto&&) { + // ... + return do_sth_future(); + }); + + // fut.get(); + } +} + +BENCHMARK(bm_future); + +int main(int argc, char** argv) { + ::benchmark::Initialize(&argc, argv); + if (::benchmark::ReportUnrecognizedArguments(argc, argv)) + return 1; + ::benchmark::RunSpecifiedBenchmarks(); + return 0; +}