feat update benchmark
This commit is contained in:
parent
669a9d794b
commit
ff8468b5d1
@ -1,3 +1,4 @@
|
|||||||
|
#include "tile/base/chrono.h"
|
||||||
#include "tile/base/random.h"
|
#include "tile/base/random.h"
|
||||||
#include "tile/fiber/detail/fiber.h"
|
#include "tile/fiber/detail/fiber.h"
|
||||||
|
|
||||||
@ -7,7 +8,7 @@ namespace fiber {
|
|||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
void Benchmark_FiberSwitch(benchmark::State &state) {
|
void Benchmark_FiberSwitch(benchmark::State &state) {
|
||||||
constexpr int kFiberCount = 10000;
|
constexpr int kFiberCount = 2 * 10000;
|
||||||
std::unique_ptr<Fiber> master;
|
std::unique_ptr<Fiber> master;
|
||||||
std::unique_ptr<Fiber> worker[kFiberCount];
|
std::unique_ptr<Fiber> worker[kFiberCount];
|
||||||
|
|
||||||
@ -16,7 +17,22 @@ void Benchmark_FiberSwitch(benchmark::State &state) {
|
|||||||
master = Fiber::Create([&]() {
|
master = Fiber::Create([&]() {
|
||||||
while (state.KeepRunning()) {
|
while (state.KeepRunning()) {
|
||||||
++cnt;
|
++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;
|
cnt = -1;
|
||||||
@ -29,6 +45,9 @@ void Benchmark_FiberSwitch(benchmark::State &state) {
|
|||||||
worker[i] = Fiber::Create([&, i]() {
|
worker[i] = Fiber::Create([&, i]() {
|
||||||
while (cnt != -1) {
|
while (cnt != -1) {
|
||||||
master->Resume();
|
master->Resume();
|
||||||
|
master->Resume();
|
||||||
|
master->Resume();
|
||||||
|
master->Resume();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -39,7 +58,7 @@ void Benchmark_FiberSwitch(benchmark::State &state) {
|
|||||||
master->Resume();
|
master->Resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
BENCHMARK(Benchmark_FiberSwitch);
|
BENCHMARK(Benchmark_FiberSwitch)->UseManualTime();
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace fiber
|
} // namespace fiber
|
||||||
} // namespace tile
|
} // namespace tile
|
||||||
|
Loading…
Reference in New Issue
Block a user