Benchmark threaded TaskGroup
| 172 | |
| 173 | // Benchmark threaded TaskGroup |
| 174 | static void ThreadedTaskGroup(benchmark::State& state) { // NOLINT non-const reference |
| 175 | const auto nthreads = static_cast<int>(state.range(0)); |
| 176 | const auto workload_size = static_cast<int32_t>(state.range(1)); |
| 177 | |
| 178 | std::shared_ptr<ThreadPool> pool; |
| 179 | pool = *ThreadPool::Make(nthreads); |
| 180 | |
| 181 | Task task(workload_size); |
| 182 | |
| 183 | const int32_t nspawns = 10000000 / workload_size + 1; |
| 184 | |
| 185 | for (auto _ : state) { |
| 186 | auto task_group = TaskGroup::MakeThreaded(pool.get()); |
| 187 | task_group->Append([&task, nspawns, task_group] { |
| 188 | for (int32_t i = 0; i < nspawns; ++i) { |
| 189 | // Pass the task by reference to avoid copying it around |
| 190 | task_group->Append(std::ref(task)); |
| 191 | } |
| 192 | return Status::OK(); |
| 193 | }); |
| 194 | ABORT_NOT_OK(task_group->Finish()); |
| 195 | } |
| 196 | ABORT_NOT_OK(pool->Shutdown(true /* wait */)); |
| 197 | |
| 198 | state.SetItemsProcessed(state.iterations() * nspawns); |
| 199 | } |
| 200 | |
| 201 | static const std::vector<int32_t> kWorkloadSizes = {1000, 10000, 100000}; |
| 202 |