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

Function autoScheduleTasks

benchmarks/ThreadPool.bench.cpp:25–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23const int REPS = 10;
24
25void autoScheduleTasks(bool enableWorkSteal) {
26 std::atomic<int> count = 0;
27 {
28 ThreadPool tp(std::thread::hardware_concurrency(), enableWorkSteal);
29
30 for (int i = 0; i < COUNT; ++i) {
31 [[maybe_unused]] auto ret = tp.scheduleById([i, &count] {
32 count++;
33 int x;
34 auto reps = REPS + (REPS * (rand() % 5));
35 for (int n = 0; n < reps; ++n)
36 x = i + rand();
37 (void)x;
38 });
39 assert(ret == ThreadPool::ERROR_TYPE::ERROR_NONE);
40 }
41 }
42 assert(count == COUNT);
43}
44
45void ThreadPool_noWorkSteal(benchmark::State& state) {
46 for ([[maybe_unused]] const auto& _ : state)

Callers 2

ThreadPool_noWorkStealFunction · 0.85
ThreadPool_withWorkStealFunction · 0.85

Calls 1

scheduleByIdMethod · 0.80

Tested by

no test coverage detected