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

Function Uthread_async

benchmarks/Uthread.bench.cpp:75–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75void Uthread_async(benchmark::State& state) {
76 async_simple::executors::SimpleExecutor executor(10);
77 auto test = [&]() {
78 auto Job = [&]() -> Future<int> {
79 Promise<int> p;
80 auto f = p.getFuture().via(&executor);
81 delayedTask(
82 &executor,
83 [p = std::move(p)]() mutable {
84 auto value = 1024;
85 p.setValue(value);
86 },
87 100);
88 return f;
89 };
90
91 constexpr size_t n = 10;
92 std::atomic<int> running = n;
93
94 for (size_t i = 0; i < n; i++)
95 async<Launch::Schedule>(
96 [&running, &Job]() {
97 await(Job());
98 running--;
99 },
100 &executor);
101
102 while (running) {
103 }
104 };
105
106 for ([[maybe_unused]] const auto& _ : state)
107 test();
108}
109
110void Uthread_await(benchmark::State& state) {
111 async_simple::executors::SimpleExecutor executor(10);

Callers

nothing calls this directly

Calls 5

delayedTaskFunction · 0.85
awaitFunction · 0.85
viaMethod · 0.80
getFutureMethod · 0.80
setValueMethod · 0.80

Tested by

no test coverage detected