8#include <memory_resource>
14 std::vector<condy::pmr::Task<void>> tasks;
15 tasks.reserve(task_count);
17 auto start = std::chrono::high_resolution_clock::now();
19 for (
size_t i = 0; i < task_count; ++i) {
23 for (
auto &task : tasks) {
24 co_await std::move(task);
27 auto end = std::chrono::high_resolution_clock::now();
28 std::chrono::duration<double> duration = end - start;
29 double tasks_per_second =
30 static_cast<double>(task_count) / duration.count();
31 std::cout <<
"Spawned and completed " << task_count <<
" tasks in "
32 << duration.count() <<
" seconds (" << tasks_per_second
33 <<
" tasks/second)\n";
36int main() noexcept(false) {
37 std::printf(
"This example is faster than benchmark spawn_tasks.cpp!!!\n");
39 const size_t task_count = 50'000'000;
41 std::pmr::monotonic_buffer_resource pool(1024l * 1024 * 100);
42 std::pmr::polymorphic_allocator<std::byte> allocator(&pool);
Main include file for the Condy library.
condy::Coro< T, std::pmr::polymorphic_allocator< std::byte > > Coro
Coroutine type using polymorphic allocator.
T sync_wait(Runtime &runtime, Coro< T, Allocator > coro)
Synchronously wait for a coroutine to complete in the given runtime.
Task< T, Allocator > co_spawn(Runtime &runtime, Coro< T, Allocator > coro)
Spawn a coroutine as a task in the given runtime.