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

Function SpinLock_thread_lock_bench

benchmarks/SpinLock.bench.cpp:54–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54void SpinLock_thread_lock_bench(benchmark::State& state) {
55 async_simple::executors::SimpleExecutor executor(50);
56 async_simple::coro::SpinLock spinlock;
57
58 int value = 0;
59 int loop_num{200};
60 std::vector<async_simple::coro::RescheduleLazy<void>> input;
61 input.reserve(loop_num);
62
63 auto test = [&]() -> async_simple::coro::Lazy<void> {
64 auto writer = [&]() -> async_simple::coro::Lazy<void> {
65 // thread lock
66 spinlock.lock();
67 value++;
68 spinlock.unlock();
69 co_return;
70 };
71 for (int i = 0; i < loop_num; i++)
72 input.emplace_back(writer().via(&executor));
73 auto combined_lazy = collectAll(std::move(input));
74 auto out = co_await std::move(combined_lazy);
75 input.clear();
76 };
77 for ([[maybe_unused]] const auto& _ : state)
78 async_simple::coro::syncAwait(test());
79}
80
81void SpinLock_coroutine_lock_bench(benchmark::State& state) {
82 async_simple::executors::SimpleExecutor executor(50);

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected