| 87 | } |
| 88 | |
| 89 | static long start_perf_test_with_atomic(size_t num_thread) { |
| 90 | butil::atomic<uint64_t> counter(0); |
| 91 | pthread_t threads[num_thread]; |
| 92 | for (size_t i = 0; i < num_thread; ++i) { |
| 93 | pthread_create(&threads[i], NULL, &add_atomic, (void *)&counter); |
| 94 | } |
| 95 | long totol_time = 0; |
| 96 | for (size_t i = 0; i < num_thread; ++i) { |
| 97 | void *ret; |
| 98 | pthread_join(threads[i], &ret); |
| 99 | totol_time += (long)ret; |
| 100 | } |
| 101 | long avg_time = totol_time / (OPS_PER_THREAD / 100 * num_thread); |
| 102 | EXPECT_EQ(2ul * num_thread * OPS_PER_THREAD / 100, counter.load()); |
| 103 | return avg_time; |
| 104 | } |
| 105 | |
| 106 | static long start_perf_test_with_adder(size_t num_thread) { |
| 107 | bvar::Adder<uint64_t> reducer; |