| 207 | } |
| 208 | |
| 209 | void test_performance(bool use_pthread) { |
| 210 | pthread_t threads[8]; |
| 211 | bthread::ExecutionQueueId<LongIntTask> queue_id = { 0 }; // to suppress warnings |
| 212 | bthread::ExecutionQueueOptions options; |
| 213 | options.use_pthread = use_pthread; |
| 214 | if (options.use_pthread) { |
| 215 | LOG(INFO) << "================ pthread ================"; |
| 216 | } else { |
| 217 | LOG(INFO) << "================ bthread ================"; |
| 218 | } |
| 219 | int64_t result = 0; |
| 220 | ASSERT_EQ(0, bthread::execution_queue_start(&queue_id, &options, |
| 221 | add, &result)); |
| 222 | PushArg pa; |
| 223 | pa.id = queue_id; |
| 224 | pa.total_num = 0; |
| 225 | pa.total_time = 0; |
| 226 | pa.expected_value = 0; |
| 227 | pa.stopped = false; |
| 228 | ProfilerStart("execq.prof"); |
| 229 | for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { |
| 230 | pthread_create(&threads[i], NULL, &push_thread_which_addresses_execq, &pa); |
| 231 | } |
| 232 | usleep(500 * 1000); |
| 233 | ASSERT_EQ(0, bthread::execution_queue_stop(queue_id)); |
| 234 | for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { |
| 235 | pthread_join(threads[i], NULL); |
| 236 | } |
| 237 | ProfilerStop(); |
| 238 | ASSERT_EQ(0, bthread::execution_queue_join(queue_id)); |
| 239 | ASSERT_EQ(pa.expected_value.load(), result); |
| 240 | LOG(INFO) << "With addressed execq, each execution_queue_execute takes " |
| 241 | << pa.total_time.load() / pa.total_num.load() |
| 242 | << " total_num=" << pa.total_num |
| 243 | << " ns with " << ARRAY_SIZE(threads) << " threads"; |
| 244 | #define BENCHMARK_BOTH |
| 245 | #ifdef BENCHMARK_BOTH |
| 246 | result = 0; |
| 247 | ASSERT_EQ(0, bthread::execution_queue_start(&queue_id, &options, |
| 248 | add, &result)); |
| 249 | pa.id = queue_id; |
| 250 | pa.total_num = 0; |
| 251 | pa.total_time = 0; |
| 252 | pa.expected_value = 0; |
| 253 | pa.stopped = false; |
| 254 | ProfilerStart("execq_id.prof"); |
| 255 | for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { |
| 256 | pthread_create(&threads[i], NULL, &push_thread, &pa); |
| 257 | } |
| 258 | usleep(500 * 1000); |
| 259 | ASSERT_EQ(0, bthread::execution_queue_stop(queue_id)); |
| 260 | for (size_t i = 0; i < ARRAY_SIZE(threads); ++i) { |
| 261 | pthread_join(threads[i], NULL); |
| 262 | } |
| 263 | ProfilerStop(); |
| 264 | ASSERT_EQ(0, bthread::execution_queue_join(queue_id)); |
| 265 | ASSERT_EQ(pa.expected_value.load(), result); |
| 266 | LOG(INFO) << "With id explicitly, execution_queue_execute takes " |
no test coverage detected