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

Function SpinLock_diff_spin_count_bench

benchmarks/SpinLock.bench.cpp:27–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25#include <vector>
26
27void SpinLock_diff_spin_count_bench(benchmark::State& state) {
28 async_simple::executors::SimpleExecutor executor(50);
29 auto spin_count = state.range(0);
30 async_simple::coro::SpinLock spinlock(spin_count);
31
32 int value = 0;
33 int loop_num{200};
34 std::vector<async_simple::coro::RescheduleLazy<void>> input;
35 input.reserve(loop_num);
36
37 auto test = [&]() -> async_simple::coro::Lazy<void> {
38 auto writer = [&]() -> async_simple::coro::Lazy<void> {
39 co_await spinlock.coLock();
40 value++;
41 spinlock.unlock();
42 co_return;
43 };
44 for (int i = 0; i < loop_num; i++)
45 input.emplace_back(writer().via(&executor));
46 auto combined_lazy = collectAll(std::move(input));
47 auto out = co_await std::move(combined_lazy);
48 input.clear();
49 };
50 for ([[maybe_unused]] const auto& _ : state)
51 async_simple::coro::syncAwait(test());
52}
53
54void SpinLock_thread_lock_bench(benchmark::State& state) {
55 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
coLockMethod · 0.45
unlockMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected