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

Function Uthread_switch

benchmarks/Uthread.bench.cpp:37–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37void Uthread_switch(benchmark::State& state) {
38 async_simple::executors::SimpleExecutor executor(10);
39 auto test = [&]() {
40 auto Job = [&]() -> Future<int> {
41 Promise<int> p;
42 auto f = p.getFuture().via(&executor);
43 delayedTask(
44 &executor,
45 [p = std::move(p)]() mutable {
46 auto value = 1024;
47 p.setValue(value);
48 },
49 100);
50 return f;
51 };
52
53 constexpr size_t n = 10;
54 std::atomic<int> running = n;
55
56 auto UthreadTask = [&executor, &running, &Job]() {
57 Uthread task(Attribute{&executor}, [&running, &Job]() {
58 await(Job());
59 running--;
60 });
61 task.detach();
62 };
63
64 for (size_t i = 0; i < n; i++)
65 executor.schedule(UthreadTask);
66
67 while (running) {
68 }
69 };
70
71 for ([[maybe_unused]] const auto& _ : state)
72 test();
73}
74
75void Uthread_async(benchmark::State& state) {
76 async_simple::executors::SimpleExecutor executor(10);

Callers

nothing calls this directly

Calls 7

delayedTaskFunction · 0.85
awaitFunction · 0.85
viaMethod · 0.80
getFutureMethod · 0.80
setValueMethod · 0.80
detachMethod · 0.45
scheduleMethod · 0.45

Tested by

no test coverage detected