diff --git a/tile/fiber/detail/fiber_benchmark.cc b/tile/fiber/detail/fiber_benchmark.cc index 1b053a2..659b22e 100644 --- a/tile/fiber/detail/fiber_benchmark.cc +++ b/tile/fiber/detail/fiber_benchmark.cc @@ -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 master; std::unique_ptr 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>( + 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