| 147 | |
| 148 | template <typename LSType, typename LRType, typename QType> |
| 149 | int test_queue_batch(const char *name, QType &queue) { |
| 150 | std::vector<std::thread> senders, receivers; |
| 151 | scnt.fill(0); |
| 152 | rcnt.fill(0); |
| 153 | auto begin = std::chrono::steady_clock::now(); |
| 154 | for (size_t i = 0; i < receiver_num; i++) { |
| 155 | receivers.emplace_back([i, &queue] { |
| 156 | photon::set_cpu_affinity(i); |
| 157 | int buffer[32]; |
| 158 | size_t size; |
| 159 | int amount = items_num / receiver_num; |
| 160 | std::chrono::nanoseconds rspent(std::chrono::nanoseconds(0)); |
| 161 | for (size_t x = 0; x < items_num / receiver_num;) { |
| 162 | auto tm = std::chrono::high_resolution_clock::now(); |
| 163 | LRType::lock(rlock); |
| 164 | while (!(size = queue.pop_batch(buffer, std::min(32, amount)))) { |
| 165 | LRType::unlock(rlock); |
| 166 | CPUPause::pause(); |
| 167 | LRType::lock(rlock); |
| 168 | } |
| 169 | LRType::unlock(rlock); |
| 170 | if (x) rspent += (std::chrono::high_resolution_clock::now() - tm) / size; |
| 171 | for (auto y: xrange(size)) { |
| 172 | rc[buffer[y]]++; |
| 173 | rcnt[i]++; |
| 174 | } |
| 175 | x += size; |
| 176 | amount -= size; |
| 177 | } |
| 178 | LOG_DEBUG("` receiver done, ` ns per action", i, |
| 179 | rspent.count() / (items_num / receiver_num - 1)); |
| 180 | }); |
| 181 | } |
| 182 | for (size_t i = 0; i < sender_num; i++) { |
| 183 | senders.emplace_back([i, &queue] { |
| 184 | photon::set_cpu_affinity(i); |
| 185 | std::vector<int> vec; |
| 186 | vec.resize(items_num / sender_num); |
| 187 | for (size_t x = 0; x < items_num / sender_num; x++) { |
| 188 | vec[x] = x; |
| 189 | } |
| 190 | size_t size; |
| 191 | std::chrono::nanoseconds wspent{std::chrono::nanoseconds(0)}; |
| 192 | for (size_t x = 0; x < items_num / sender_num;) { |
| 193 | auto tm = std::chrono::high_resolution_clock::now(); |
| 194 | LSType::lock(wlock); |
| 195 | while (!(size = queue.push_batch(&vec[x], std::min(32UL, vec.size() - x)))) { |
| 196 | LSType::unlock(wlock); |
| 197 | CPUPause::pause(); |
| 198 | LSType::lock(wlock); |
| 199 | } |
| 200 | LSType::unlock(wlock); |
| 201 | wspent += (std::chrono::high_resolution_clock::now() - tm) / size; |
| 202 | for (auto y = x; y < x + size; y++) { |
| 203 | sc[y] ++; |
| 204 | scnt[i] ++; |
| 205 | } |
| 206 | x += size; |
nothing calls this directly
no test coverage detected