mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 16:56:44 +08:00
Implement a benchmark against boost::future
This commit is contained in:
parent
2b4f31c121
commit
2cfbdaf673
@ -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()
|
||||
|
||||
@ -2,3 +2,4 @@ add_subdirectory(playground)
|
||||
add_subdirectory(threads)
|
||||
add_subdirectory(unit-test)
|
||||
add_subdirectory(mock)
|
||||
add_subdirectory(simple-benchmark)
|
||||
|
||||
16
test/simple-benchmark/CMakeLists.txt
Normal file
16
test/simple-benchmark/CMakeLists.txt
Normal file
@ -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)
|
||||
61
test/simple-benchmark/benchmark-simple.cpp
Normal file
61
test/simple-benchmark/benchmark-simple.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <continuable/continuable.hpp>
|
||||
|
||||
static auto do_sth_continuable() {
|
||||
return cti::make_continuable<void>([](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<void> do_sth_future() {
|
||||
boost::promise<void> p;
|
||||
boost::future<void> 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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user