MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / TEST

Function TEST

src/core/test/utils/thread.cpp:70–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68} // namespace
69
70TEST(TestAsyncQueue, Synchronizer) {
71 size_t nr_worker_call = 0;
72 SCQueueSynchronizer sync(0);
73 auto worker = [&]() {
74 for (;;) {
75 auto nr = sync.consumer_fetch(1);
76 if (!nr)
77 return;
78 nr_worker_call += nr;
79 ASSERT_EQ(1u, nr);
80 sync.consumer_commit(nr);
81 }
82 };
83 sync.start_worker(std::thread{worker});
84
85 constexpr size_t N = 3000000;
86 RealTimer timer;
87 for (size_t i = 0; i < N; ++i) {
88 sync.producer_add();
89 }
90 auto tadd = timer.get_secs_reset() * 1e9 / N;
91 sync.producer_wait();
92 auto twait = timer.get_secs_reset() * 1e9 / N;
93 ASSERT_EQ(N, nr_worker_call);
94 printf("tadd=%.3f twait=%.3f [ns]\n", tadd, twait);
95}
96
97TEST(TestAsyncQueue, SynchronizerWaitOverhead) {
98 {

Callers

nothing calls this directly

Calls 15

consumer_fetchMethod · 0.80
consumer_commitMethod · 0.80
producer_addMethod · 0.80
producer_waitMethod · 0.80
joinMethod · 0.80
emplace_backMethod · 0.80
fFunction · 0.50
funcFunction · 0.50
start_workerMethod · 0.45
get_secs_resetMethod · 0.45
get_msecsMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected