9#include <memory_resource>
15 std::vector<condy::pmr::Task<void>> tasks;
16 tasks.reserve(task_count);
18 auto start = std::chrono::high_resolution_clock::now();
20 for (
size_t i = 0; i < task_count; ++i) {
24 for (
auto &task : tasks) {
25 co_await std::move(task);
28 auto end = std::chrono::high_resolution_clock::now();
29 std::chrono::duration<double> duration = end - start;
30 double tasks_per_second =
31 static_cast<double>(task_count) / duration.count();
32 std::cout << std::format(
"Spawned and completed {} tasks in {:.2f} seconds "
33 "({:.2f} tasks/second)\n",
34 task_count, duration.count(), tasks_per_second);
37int main() noexcept(false) {
38 std::cout <<
"This example is faster than benchmark spawn_tasks.cpp!!!\n";
40 const size_t task_count = 50'000'000;
42 std::pmr::monotonic_buffer_resource pool(1024l * 1024 * 100);
43 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.