This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <exe/tp/thread_pool.hpp> | |
#include <exe/fibers/core/api.hpp> | |
#include <wheels/support/assert.hpp> | |
#include <chrono> | |
#include <iostream> | |
using namespace exe; | |
int main() { | |
constexpr size_t kThreadCount = 4; | |
constexpr size_t kFiberCount = 5000; | |
tp::ThreadPool scheduler{kThreadCount}; | |
using Clock = std::chrono::system_clock; | |
using Seconds = std::chrono::duration<double, std::milli>; | |
const auto start = Clock::now(); | |
std::atomic<uint64_t> counter{0}; | |
for (size_t ii = 0; ii < kThreadCount; ++ii) { | |
fibers::Go(scheduler, [&] { | |
for (size_t jj = 0; jj < kFiberCount; ++jj) { | |
fibers::Go([&] { | |
++counter; | |
}); | |
} | |
}); | |
} | |
scheduler.WaitIdle(); | |
scheduler.Stop(); | |
const Seconds elapsed = Clock::now() - start; | |
std::cout << "Running fibers took " << elapsed.count() << " ms" << std::endl; | |
WHEELS_VERIFY(counter == kThreadCount * kFiberCount, "Bogus counter: " << counter); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment