Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,18 @@ else()
message(STATUS "Building unit tests!")
add_executable(async_unit_test)
# Add module files
target_sources(async_unit_test
PRIVATE
target_sources(async_unit_test PUBLIC
FILE_SET CXX_MODULES
TYPE CXX_MODULES
FILES
tests/util.cppm
PRIVATE
tests/main.test.cpp
tests/async.test.cpp
tests/basics.test.cpp
tests/blocked_by.test.cpp
tests/cancel.test.cpp
tests/guards.test.cpp
tests/proxy.test.cpp
)

target_compile_features(async_unit_test PUBLIC cxx_std_23)
Expand Down
38 changes: 30 additions & 8 deletions benchmarks/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,27 @@ static void bm_virtual_call_variant(benchmark::State& state)
}
BENCHMARK(bm_virtual_call_variant);

/**
* @brief Sync wait a future
*
* This is only safe is the operation never blocks by time. For this benchmark,
* that should always be the case.
*
* @tparam T - type of the future
* @param p_future - future to finish
* @return auto - result T
*/
template<typename T>
auto sync_wait(async::future<T>& p_future)
{
while (not p_future.done()) {
p_future.resume();
}
if constexpr (not std::is_void_v<T>) {
return std::move(p_future.value());
}
}

// ----------------------------------------------------------------------------
// 3. FUTURE SYNC: Non-coroutine functions returning future<int>, 3 levels deep
// These functions directly construct future with a value (no coroutine)
Expand All @@ -238,15 +259,15 @@ __attribute__((noinline)) async::future<int> sync_future_level2(
int x)
{
auto f = sync_future_level3(ctx, x);
return f.sync_wait() + 1;
return sync_wait(f) + 1;
}

__attribute__((noinline)) async::future<int> sync_future_level1(
async::context& ctx,
int x)
{
auto f = sync_future_level2(ctx, x);
return f.sync_wait() + 1;
return sync_wait(f) + 1;
}
struct benchmark_context : public async::context
{
Expand All @@ -271,7 +292,7 @@ static void bm_future_sync_return(benchmark::State& state)
int input = 42;
for (auto _ : state) {
auto f = sync_future_level1(ctx, input);
int result = f.sync_wait();
int result = sync_wait(f);
benchmark::DoNotOptimize(result);
}
}
Expand Down Expand Up @@ -308,7 +329,7 @@ static void bm_future_coroutine(benchmark::State& state)
int input = 42;
for (auto _ : state) {
auto f = coro_level1(ctx, input);
int result = f.sync_wait();
int result = sync_wait(f);
benchmark::DoNotOptimize(result);
}
}
Expand Down Expand Up @@ -349,7 +370,7 @@ static void bm_future_sync_await(benchmark::State& state)
int input = 42;
for (auto _ : state) {
auto f = sync_in_coro_level1(ctx, input);
int result = f.sync_wait();
int result = sync_wait(f);
benchmark::DoNotOptimize(result);
}
}
Expand All @@ -370,7 +391,8 @@ __attribute__((noinline)) async::future<int> mixed_sync_level2(
async::context& ctx,
int x)
{
return mixed_sync_level3(ctx, x).sync_wait() + 1;
auto future = mixed_sync_level3(ctx, x);
return sync_wait(future) + 1;
}

__attribute__((noinline)) async::future<int> mixed_coro_level1(
Expand All @@ -389,7 +411,7 @@ static void bm_future_mixed(benchmark::State& state)
int input = 42;
for (auto _ : state) {
auto f = mixed_coro_level1(ctx, input);
int result = f.sync_wait();
int result = sync_wait(f);
benchmark::DoNotOptimize(result);
}
}
Expand Down Expand Up @@ -431,7 +453,7 @@ static void bm_future_void_coroutine(benchmark::State& state)
int output = 0;
for (auto _ : state) {
auto f = void_coro_level1(ctx, output, input);
f.sync_wait();
sync_wait(f);
benchmark::DoNotOptimize(f);
benchmark::DoNotOptimize(output);
}
Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class async_context_conan(ConanFile):
description = ("Implementation of C++20 coroutines targeting embedded system by eliminating the usage of the global heap and providing a 'context' which contains a coroutine stack frame and other useful utilities for scheduling.")
topics = ("async", "coroutines", "stack", "scheduling", "scheduler")
settings = "compiler", "build_type", "os", "arch"
exports_sources = "modules/*", "benchmarks/*", "tests/*", "CMakeLists.txt", "*.cmake.in", "LICENSE"
exports_sources = "modules/*", "benchmarks/*", "tests/*", "CMakeLists.txt", "LICENSE"
package_type = "static-library"
shared = False

Expand Down
Loading