| 79 | } |
| 80 | |
| 81 | void 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 | } |