MCPcopy Create free account
hub / github.com/apache/arrow / ThreadPoolSubmit

Function ThreadPoolSubmit

cpp/src/arrow/util/thread_pool_benchmark.cc:123–152  ·  view source on GitHub ↗

Benchmark ThreadPool::Submit

Source from the content-addressed store, hash-verified

121
122// Benchmark ThreadPool::Submit
123static void ThreadPoolSubmit(benchmark::State& state) { // NOLINT non-const reference
124 const auto nthreads = static_cast<int>(state.range(0));
125 const auto workload_size = static_cast<int32_t>(state.range(1));
126
127 Workload workload(workload_size);
128
129 const int32_t nspawns = 10000000 / workload_size + 1;
130
131 for (auto _ : state) {
132 state.PauseTiming();
133 auto pool = *ThreadPool::Make(nthreads);
134 std::atomic<int32_t> n_finished{0};
135 state.ResumeTiming();
136
137 for (int32_t i = 0; i < nspawns; ++i) {
138 // Pass the task by reference to avoid copying it around
139 (void)DeferNotOk(pool->Submit(std::ref(workload))).Then([&]() {
140 n_finished.fetch_add(1);
141 });
142 }
143
144 // Wait for all tasks to finish
145 ABORT_NOT_OK(pool->Shutdown(true /* wait */));
146 ASSERT_EQ(n_finished.load(), nspawns);
147 state.PauseTiming();
148 pool.reset();
149 state.ResumeTiming();
150 }
151 state.SetItemsProcessed(state.iterations() * nspawns);
152}
153
154// Benchmark serial TaskGroup
155static void SerialTaskGroup(benchmark::State& state) { // NOLINT non-const reference

Callers

nothing calls this directly

Calls 7

DeferNotOkFunction · 0.85
refFunction · 0.85
ThenMethod · 0.80
MakeFunction · 0.70
ShutdownMethod · 0.45
loadMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected