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

Function run_loop

example/use-counter-with-bvar/example.cpp:21–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19
20template <typename S>
21void 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
53template <typename V>
54void run(::std::string prefix) {

Callers

nothing calls this directly

Calls 6

run_onceFunction · 0.85
emplace_backMethod · 0.80
exposeMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected