| 19 | |
| 20 | template <typename S> |
| 21 | void run_loop(::std::string prefix) { |
| 22 | S s; |
| 23 | s.expose("test-" + prefix + "_var"); |
| 24 | ::bvar::LatencyRecorder latency {"test-" + prefix}; |
| 25 | |
| 26 | ::std::vector<uint32_t> values; |
| 27 | values.resize(FLAGS_loop); |
| 28 | ::std::mt19937_64 gen {::std::random_device {}()}; |
| 29 | ::std::normal_distribution<> dis {600, 100}; |
| 30 | for (auto& value : values) { |
| 31 | value = dis(gen); |
| 32 | } |
| 33 | |
| 34 | ::std::vector<::std::thread> threads; |
| 35 | for (size_t i = 0; i < FLAGS_concurrency; ++i) { |
| 36 | threads.emplace_back([&] { |
| 37 | while (!::brpc::IsAskedToQuit()) { |
| 38 | auto begin = ::butil::cpuwide_time_ns(); |
| 39 | for (auto value : values) { |
| 40 | run_once(s.var, value); |
| 41 | } |
| 42 | auto end = ::butil::cpuwide_time_ns(); |
| 43 | latency << (end - begin) * 1000.0 / values.size(); |
| 44 | } |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | for (auto& thread : threads) { |
| 49 | thread.join(); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | template <typename V> |
| 54 | void run(::std::string prefix) { |