feat/support_fiber #2
@ -1,3 +1,4 @@
|
||||
#include "tile/base/chrono.h"
|
||||
#include "tile/base/random.h"
|
||||
#include "tile/fiber/detail/fiber.h"
|
||||
|
||||
@ -7,7 +8,7 @@ namespace fiber {
|
||||
namespace detail {
|
||||
|
||||
void Benchmark_FiberSwitch(benchmark::State &state) {
|
||||
constexpr int kFiberCount = 10000;
|
||||
constexpr int kFiberCount = 2 * 10000;
|
||||
std::unique_ptr<Fiber> master;
|
||||
std::unique_ptr<Fiber> worker[kFiberCount];
|
||||
|
||||
@ -16,7 +17,22 @@ void Benchmark_FiberSwitch(benchmark::State &state) {
|
||||
master = Fiber::Create([&]() {
|
||||
while (state.KeepRunning()) {
|
||||
++cnt;
|
||||
worker[Random(kFiberCount - 1)]->Resume();
|
||||
auto &w1 = worker[Random(kFiberCount - 1)];
|
||||
auto &w2 = worker[Random(kFiberCount - 1)];
|
||||
auto start = ReadSteadyClock();
|
||||
w1->Resume();
|
||||
w2->Resume();
|
||||
w1->Resume();
|
||||
w2->Resume();
|
||||
w1->Resume();
|
||||
w2->Resume();
|
||||
w1->Resume();
|
||||
w2->Resume();
|
||||
auto end = ReadSteadyClock();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::duration<double>>(
|
||||
end - start) /
|
||||
8;
|
||||
state.SetIterationTime(duration.count());
|
||||
}
|
||||
|
||||
cnt = -1;
|
||||
@ -29,6 +45,9 @@ void Benchmark_FiberSwitch(benchmark::State &state) {
|
||||
worker[i] = Fiber::Create([&, i]() {
|
||||
while (cnt != -1) {
|
||||
master->Resume();
|
||||
master->Resume();
|
||||
master->Resume();
|
||||
master->Resume();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -39,7 +58,7 @@ void Benchmark_FiberSwitch(benchmark::State &state) {
|
||||
master->Resume();
|
||||
}
|
||||
|
||||
BENCHMARK(Benchmark_FiberSwitch);
|
||||
BENCHMARK(Benchmark_FiberSwitch)->UseManualTime();
|
||||
} // namespace detail
|
||||
} // namespace fiber
|
||||
} // namespace tile
|
||||
|
Loading…
x
Reference in New Issue
Block a user