MCPcopy Create free account
hub / github.com/alibaba/async_simple / SpinLock_coroutine_lock_bench

Function SpinLock_coroutine_lock_bench

benchmarks/SpinLock.bench.cpp:81–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81void SpinLock_coroutine_lock_bench(benchmark::State& state) {
82 async_simple::executors::SimpleExecutor executor(50);
83 async_simple::coro::SpinLock spinlock;
84
85 int value = 0;
86 int loop_num{200};
87 std::vector<async_simple::coro::RescheduleLazy<void>> input;
88 input.reserve(loop_num);
89
90 auto test = [&]() -> async_simple::coro::Lazy<void> {
91 auto writer = [&]() -> async_simple::coro::Lazy<void> {
92 // coroutine lock
93 co_await spinlock.coLock();
94 value++;
95 spinlock.unlock();
96 co_return;
97 };
98 for (int i = 0; i < loop_num; i++)
99 input.emplace_back(writer().via(&executor));
100 auto combined_lazy = collectAll(std::move(input));
101 auto out = co_await std::move(combined_lazy);
102 input.clear();
103 };
104 for ([[maybe_unused]] const auto& _ : state)
105 async_simple::coro::syncAwait(test());
106}

Callers

nothing calls this directly

Calls 7

syncAwaitFunction · 0.85
viaMethod · 0.80
collectAllFunction · 0.50
reserveMethod · 0.45
coLockMethod · 0.45
unlockMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected