MCPcopy Create free account
hub / github.com/baidu/babylon / TEST

Function TEST

test/concurrent/test_bounded_queue_press_mpmc.cpp:11–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9using ::babylon::ConcurrentBoundedQueue;
10
11TEST(concurrent_bounded_queue, press_blocking_mpmc) {
12 size_t batch_size = 10;
13 size_t batch_concurrent = 32;
14 size_t single_concurrent = 32;
15 size_t times = 10;
16 ConcurrentBoundedQueue<size_t> queue {batch_concurrent + single_concurrent};
17
18 ::std::vector<::std::future<size_t>> push_futures;
19 push_futures.reserve(batch_concurrent + single_concurrent);
20 for (size_t i = 0; i < batch_concurrent; ++i) {
21 push_futures.emplace_back(::std::async(::std::launch::async, [&] {
22 ::std::mt19937 gen(::std::random_device {}());
23 size_t sum = 0;
24 size_t vec[batch_size];
25 for (size_t j = 0; j < times; ++j) {
26 size_t value = gen();
27 ::std::fill_n(vec, batch_size, value);
28 queue.push_n(vec, vec + batch_size);
29 sum += value * batch_size;
30 }
31 return sum;
32 }));
33 }
34 for (size_t i = 0; i < single_concurrent; ++i) {
35 push_futures.emplace_back(::std::async(::std::launch::async, [&] {
36 ::std::mt19937 gen(::std::random_device {}());
37 size_t sum = 0;
38 for (size_t j = 0; j < times; ++j) {
39 size_t value = gen();
40 queue.push(value);
41 sum += value;
42 }
43 return sum;
44 }));
45 }
46
47 ::std::vector<::std::future<size_t>> pop_futures;
48 pop_futures.reserve(batch_concurrent + single_concurrent);
49 for (size_t i = 0; i < batch_concurrent; ++i) {
50 pop_futures.emplace_back(::std::async(::std::launch::async, [&] {
51 size_t sum = 0;
52 size_t vec[batch_size];
53 for (size_t j = 0; j < times; ++j) {
54 queue.pop_n(vec, vec + batch_size);
55 for (size_t k = 0; k < batch_size; ++k) {
56 sum += vec[k];
57 }
58 }
59 return sum;
60 }));
61 }
62 for (size_t i = 0; i < single_concurrent; ++i) {
63 pop_futures.emplace_back(::std::async(::std::launch::async, [&] {
64 size_t sum = 0;
65 for (size_t j = 0; j < times; ++j) {
66 size_t v = 0;
67 queue.pop(v);
68 sum += v;

Callers

nothing calls this directly

Calls 8

asyncFunction · 0.85
emplace_backMethod · 0.80
push_nMethod · 0.80
pop_nMethod · 0.80
reserveMethod · 0.45
pushMethod · 0.45
popMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected