| 52 | } |
| 53 | |
| 54 | void 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 | |
| 81 | void SpinLock_coroutine_lock_bench(benchmark::State& state) { |
| 82 | async_simple::executors::SimpleExecutor executor(50); |